Async-Redis
view release on metacpan or search on metacpan
examples/pagi-chat/README.md view on Meta::CPAN
# Stop Redis
docker compose -f examples/docker-compose.yml down
# Stop and remove data
docker compose -f examples/docker-compose.yml down -v
```
Or using docker directly:
```bash
docker run -d -p 6379:6379 --name redis-example redis:7-alpine
```
### 2. Run the Chat Server
```bash
# Run with multiple workers
REDIS_HOST=localhost pagi-server \
--app examples/pagi-chat/app.pl \
--port 5000 \
--workers 4
```
### 3. Test Multi-Worker Chat
Open http://localhost:5000 in multiple browser tabs. Messages sent from one tab
will be received by all other tabs, even though they may be connected to different
worker processes.
## What This Demonstrates
- **Async::Redis** working with PAGI
- **Fork-safe connections** - each worker creates its own Redis connections
- **PubSub** for real-time cross-worker message delivery
- **Redis data structures** for shared state (hashes, sets, lists)
- **Non-blocking I/O** throughout with async/await
## Files
```
examples/pagi-chat/
âââ app.pl # Main PAGI application
âââ lib/
â âââ ChatApp/
â âââ State.pm # Redis-backed state management
â âââ WebSocket.pm # WebSocket chat handler
â âââ HTTP.pm # Static files and API
âââ public/
âââ index.html
âââ css/style.css
âââ js/app.js
```
## Comparison with Original
| Feature | Original (In-Memory) | This Version (Redis) |
|---------|---------------------|----------------------|
| Workers | 1 only | N workers |
| State | Process memory | Redis |
| Broadcast | Direct callbacks | Redis PubSub |
| Persistence | None (lost on restart) | Redis (survives restart) |
| Scalability | Single process | Horizontal |
## Requirements
- PAGI (0.001+)
- Async::Redis
- Redis server
- JSON::MaybeXS
( run in 0.598 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )