0
0
Redisquery~5 mins

UNSUBSCRIBE behavior in Redis

Choose your learning style9 modes available
Introduction

UNSUBSCRIBE lets you stop listening to messages from one or more channels in Redis. It helps you control which messages you get.

When you no longer want to receive updates from a chat room channel.
When your app needs to stop tracking a topic to save resources.
When a user leaves a live event and you want to stop sending them event messages.
When you want to switch from one channel to another without closing the connection.
Syntax
Redis
UNSUBSCRIBE [channel-1 channel-2 ...]
If no channels are specified, UNSUBSCRIBE unsubscribes from all channels.
UNSUBSCRIBE sends a confirmation message for each channel unsubscribed.
Examples
Stops listening to the 'sports' channel only.
Redis
UNSUBSCRIBE sports
Stops listening to both 'news' and 'weather' channels.
Redis
UNSUBSCRIBE news weather
Stops listening to all subscribed channels.
Redis
UNSUBSCRIBE
Sample Program

This subscribes to 'news' and 'sports' channels, then unsubscribes from 'sports'. You will still receive messages from 'news'.

Redis
SUBSCRIBE news sports
UNSUBSCRIBE sports
OutputSuccess
Important Notes

UNSUBSCRIBE does not close the connection; it only stops messages from specified channels.

You receive a message confirming each channel you unsubscribe from, showing how many channels remain subscribed.

Summary

UNSUBSCRIBE stops message delivery from one or more channels.

Without arguments, it unsubscribes from all channels.

It helps manage which messages your client receives without disconnecting.