Reputation: 1985
I can't find any way to subscribe other channels after entered the "pub/sub" mode when using the redis-cli. For example:
$ redis-cli
redis> SUBSCRIBE channel:1
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel:1"
3) (integer) 1
When I press Ctrl-C, the redis-cli is quit instead of "pub/sub" mode. Does anyone know how to solve the problem?
Upvotes: 5
Views: 8058
Reputation: 17567
It is the problem of redis-cli
, not Redis.
Redis says that we are allowed to issue SUBSCRIBE
s after issuing one SUBSCRIBE
. However, the redis-cli
will block everything.
Thus, as suggested by @user1611552, we can use
telnet localhost 6379
instead of redis-cli
, and everything would be fine.
Upvotes: 0
Reputation: 621
Actually, SUBSCRIBE and PSUBSCRIBE will both block all subsequent commands, thus you can't ship any order to the server but cast your eager gaze back to wait your interested channel for the incoming message. Well, This ridiculous behavior makes my head spin also.
However, if you try to access redis by means of telnet telnet localhost 6379
instead of redis-cli. Everything will be OK. check it out plz.
Upvotes: 3
Reputation: 39223
AFAIK, you can't issue new commands in redis-cli after subscribing to a channel. However, the SUBSCRIBE command is variadic since version 2.4, meaning you can pass several channels at once, to subscribe to:
redis 127.0.0.1:6379> SUBSCRIBE channel:1 channel:2
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel:1"
3) (integer) 1
1) "subscribe"
2) "channel:2"
3) (integer) 2
Upvotes: 4