Redis - PubSub Psubscribe Command



Redis PSUBSCRIBE command is used to subscribe to channels matching the given patterns.

Syntax

Following is the basic syntax of Redis PSUBSCRIBE command.

redis 127.0.0.1:6379> PSUBSCRIBE CHANNEL_NAME_OR_PATTERN [PATTERN...]

Following listing shows some supported patterns in Redis.

  • h?llo subscribes to hello, hallo and hxllo
  • h*llo subscribes to hllo and heeeello
  • h[ae]llo subscribes to hello and hallo, but not hillo

Example

redis 127.0.0.1:6379> PSUBSCRIBE mychannel 
Reading messages... (press Ctrl-C to quit) 
1) "psubscribe" 
2) "mychannel" 
3) (integer) 1 
redis_pub_sub.htm
Advertisements