Redis PUNSUBSCRIBE – How to unsubscribe from multiple patterns in redis pub/sub
2 months ago Lalit Bhagtani 0
In this tutorial, we will learn about how to unsubscribe from multiple patterns in redis message broker system using redis-cli.
The PUNSUBSCRIBE command is used to unsubscribe the client from one or more specified patterns in redis message broker system. If no patterns are specified, then client is unsubscribed from all the subscribed patterns. It returns a message for every unsubscribed pattern.
The syntax of redis PUNSUBSCRIBE command is as follows :-
redis host:post> PUNSUBSCRIBE <pattern> [ <pattern> ]
- (array) reply of 3 elements.
Format of Pushed Message :-
A message is a array reply with three elements. The first element of the array reply is punsubscribe which means that we have successfully unsubscribed from the pattern given as the second element in the reply. The third argument represents the number of patterns we are currently subscribed to. When the last argument is zero, client is no longer subscribe to any pattern, and it can issue any redis command as it is outside of subscribed state.
That’s all for how to unsubscribe from one or more patterns in redis message broker using redis-cli. If you liked it, please share your thoughts in comments section and share it with others too.