0
0
Redisquery~5 mins

SUBSCRIBE to channels in Redis

Choose your learning style9 modes available
Introduction

SUBSCRIBE lets you listen to messages sent to specific channels in Redis. It helps you get real-time updates.

You want to get live notifications when new data arrives.
You need to update a chat app instantly when someone sends a message.
You want to trigger actions when certain events happen in your system.
You want to monitor logs or alerts as they happen.
You want to build a simple publish-subscribe messaging system.
Syntax
Redis
SUBSCRIBE channel1 [channel2 ...]
You can subscribe to one or more channels at the same time.
Once subscribed, the connection listens continuously for messages.
Examples
Subscribe to a single channel named 'news'.
Redis
SUBSCRIBE news
Subscribe to two channels: 'sports' and 'weather'.
Redis
SUBSCRIBE sports weather
Sample Program

This command subscribes the client to the 'updates' channel. The client will receive all messages published to 'updates'.

Redis
SUBSCRIBE updates
OutputSuccess
Important Notes

When subscribed, the client cannot run other commands until it unsubscribes.

Messages published to the channel will be received as: ["message", channel, message].

Use UNSUBSCRIBE to stop listening to channels.

Summary

SUBSCRIBE connects you to channels to receive live messages.

You can listen to multiple channels at once.

It is useful for real-time communication and event handling.