0
0
Redisquery~30 mins

Pub/sub vs streams comparison in Redis - Hands-On Comparison

Choose your learning style9 modes available
Understanding Pub/Sub and Streams in Redis
📖 Scenario: You are building a simple notification system using Redis. You want to learn how to use Redis Pub/Sub and Streams to send and receive messages.
🎯 Goal: Build two small Redis data structures: one using Pub/Sub channels and one using Streams. Learn how to publish messages and read them using both methods.
📋 What You'll Learn
Create a Pub/Sub channel named notifications
Publish a message 'Hello Pub/Sub!' to the notifications channel
Create a Stream named mystream
Add a message with field message and value 'Hello Streams!' to mystream
💡 Why This Matters
🌍 Real World
Redis Pub/Sub is great for real-time notifications like chat messages or live updates. Streams are useful for event sourcing, logging, and reliable message processing.
💼 Career
Understanding Redis Pub/Sub and Streams is valuable for backend developers working on scalable, real-time applications and data pipelines.
Progress0 / 4 steps
1
Create a Pub/Sub channel and publish a message
Use the Redis command PUBLISH to send the message 'Hello Pub/Sub!' to the channel named notifications.
Redis
Need a hint?

Use the PUBLISH command followed by the channel name and the message in single quotes.

2
Create a Stream and add a message
Use the Redis command XADD to add a message to the Stream named mystream. The message should have the field message with the value 'Hello Streams!'. Use * for the ID to let Redis generate it.
Redis
Need a hint?

The XADD command adds entries to a stream. Use * to auto-generate the ID.

3
Subscribe to the Pub/Sub channel
Use the Redis command SUBSCRIBE to listen to messages on the channel named notifications.
Redis
Need a hint?

The SUBSCRIBE command listens for messages on a channel.

4
Read messages from the Stream
Use the Redis command XREAD to read new messages from the Stream named mystream. Use STREAMS mystream 0 to read all messages from the beginning.
Redis
Need a hint?

The XREAD command reads messages from streams. Use 0 to read from the start.