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 )