Publish and subscribe to Redis
Subscribers can subscribe to the message types they are interested in from redis server through the subscribe and psubscribe commands. Redis refers to the information type as a channel. When the publisher sends a specific type of information to the redis server through the publish command, the full client that subscribes to that information type will receive this message.
Session 1: monitoring channel 1
127.0.0.1 purl 6379 > subscribe tv1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
Session 2: monitoring channels 1 and 2
127.0.0.1 purl 6379 > subscribe tv1 tv2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
1) "subscribe"
2) "tv2"
3) (integer) 2
Session 3: post information on channel 1
127.0.0.1 purl 6379 > publish tv1 stone
(integer) 2
View session 1:
127.0.0.1 purl 6379 > subscribe tv1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
1) "message"
2) "tv1"
3) "stone"
View session 2:
127.0.0.1 purl 6379 > subscribe tv1 tv2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
1) "subscribe"
2) "tv2"
3) (integer) 2
1) "message"
2) "tv1"
3) "stone"
Session 3: post information on channel 2
127.0.0.1 purl 6379 > publish tv2 stone2
(integer) 1
View session 2:
127.0.0.1 purl 6379 > subscribe tv1 tv2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "tv1"
3) (integer) 1
1) "subscribe"
2) "tv2"
3) (integer) 2
1) "message"
2) "tv1"
3) "stone"
1) "message"
2) "tv2"
3) "stone2