This is a Redis starter template for JS and Node, adapted for a matchmaking and game session state demo using:
Copy the example environment file:
cp .env.example .envThe app uses Redis on redis://localhost:6379 by default when you run it outside Docker.
Start the stack with Docker:
bun dockerThe API listens on http://localhost:8080.
The matchmaking service exposes these routes:
POST /api/matchmaking/modes/:mode/join- Join the queue for a mode and skill levelGET /api/matchmaking/modes/:mode/queue?skill=<skill>- Inspect the queue for a skill bucketGET /api/matchmaking/rooms/:roomId- Read a room by IDPATCH /api/matchmaking/rooms/:roomId- Update room status and winner
Run the full test suite with:
bun testThe tests start Redis through Docker, reset the database between cases, and exercise the matchmaking queue and room lifecycle.
bun install
bun dev- Queue membership is stored in Redis sorted sets, grouped by mode and skill bucket.
- Player state is stored in Redis hashes while the player waits in queue.
- The join-and-match flow uses
WATCHandMULTIfor optimistic locking so concurrent requests cannot double-match players. - Matched rooms are stored as JSON strings with a TTL so stale rooms expire automatically.
- Room updates use
WATCHandMULTIto guard against concurrent patches. - Room lifecycle events are published to Redis Pub/Sub on
matchmaking:events.