将消息发布到特定通道。
redis 127.0.0.1:6379> PUBLISH channel message
(integer) 0使用另一个Redis客户端,我订阅了该频道。
redis 127.0.0.1:6379> SUBSCRIBE channel
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "channel"
3) (integer) 1在Redis客户端,我得到了所有发布的消息。现在我想取消订阅已订阅的频道。但是我不能在Redis客户端输入取消订阅。当我使用Ctrl+c时,完全Redis客户端退出。如何在Redis客户端编写取消订阅命令?
发布于 2013-06-21 16:21:17
我认为你不能在客户端发出取消订阅,因为客户端被阻塞了。我写了一个ruby脚本来展示如何使用退订。
require 'redis'
r = Redis.new
r.subscribe 'first' do |on|
on.message do |e, d|
puts e
puts d
r.unsubscribe
end
end
puts "script was blocked?"如果删除r.unsubscribe,脚本将被阻止。您还可以添加if子句来检查何时取消订阅client.ex:
r.unsubscribe if d == 'leave'https://stackoverflow.com/questions/15633634
复制相似问题