Pub/Sub & StreamsBeginner
1Question 1 of 1
bashHow do Redis Pub/Sub and Redis Streams differ for messaging architectures?
Explanation & Concept
• Pub/Sub (`PUBLISH`, `SUBSCRIBE`): A fire-and-forget message broker. If a subscriber is offline or disconnected when a message is published, the message is permanently lost. Messages are not persisted to memory or disk. • Redis Streams (`XADD`, `XREADGROUP`): An append-only log structure modeled after Apache Kafka. Messages are persisted, support consumer groups, acknowledge delivery (`XACK`), and allow consumers to resume reading from any point in the history after a restart.
Code Example
bash
# Redis Streams Example: Producer adds event
XADD orders_stream * customer_id 902 total 129.99
# Consumer Group reads next unread message
XREADGROUP GROUP billing_workers worker_1 COUNT 1 STREAMS orders_stream >
# Acknowledge completion of task
XACK orders_stream billing_workers "1695000000000-0"How It Works & Key Takeaways
Redis Streams provide guaranteed delivery and parallel load-balancing among worker instances, unlike traditional ephemeral Pub/Sub.
Mock Test · 1 Questions · Optional
Ready for Persistence (RDB/AOF)?
Take a quick test to evaluate yourself, or move straight to the next module.
Beginner1 questions