Simple publish-subscribe for notifications.
Basics¶
PUBLISH notifications '{"user":1,"msg":"New message"}'
SUBSCRIBE notifications
PSUBSCRIBE notifications:*
Limitations¶
- Fire-and-forget
- Offline = lost messages
- No persistence
- For reliable → Streams or Kafka
Use cases: - Real-time notifications - Chat - Cache invalidation
Architecture and Limitations¶
Redis Pub/Sub works on a fire-and-forget principle — messages are delivered only to clients that are currently connected and subscribed to the channel. If a subscriber restarts or loses connection, messages sent in the meantime are lost. There is no backlog or replay mechanism.
Pattern subscribe (PSUBSCRIBE) allows subscribing to multiple channels at once using wildcards. For example, PSUBSCRIBE notifications:* captures messages from notifications:user:1 and notifications:system. For cache invalidation, Pub/Sub is ideal — when data changes, you publish a message and all application instances invalidate their local cache. For reliable message delivery with at-least-once guarantees, use Redis Streams, which offer consumer groups and acknowledgment.
Pub/Sub for Simple Real-time¶
For reliable messaging use Redis Streams.