class Redis::SubscribedClient

Public Class Methods

new(client) click to toggle source
# File lib/redis/subscribe.rb, line 5
def initialize(client)
  @client = client
end

Public Instance Methods

call(command) click to toggle source
# File lib/redis/subscribe.rb, line 9
def call(command)
  @client.process([command])
end
psubscribe(*channels, &block) click to toggle source
# File lib/redis/subscribe.rb, line 21
def psubscribe(*channels, &block)
  subscription("psubscribe", "punsubscribe", channels, block)
end
psubscribe_with_timeout(timeout, *channels, &block) click to toggle source
# File lib/redis/subscribe.rb, line 25
def psubscribe_with_timeout(timeout, *channels, &block)
  subscription("psubscribe", "punsubscribe", channels, block, timeout)
end
punsubscribe(*channels) click to toggle source
# File lib/redis/subscribe.rb, line 33
def punsubscribe(*channels)
  call([:punsubscribe, *channels])
end
subscribe(*channels, &block) click to toggle source
# File lib/redis/subscribe.rb, line 13
def subscribe(*channels, &block)
  subscription("subscribe", "unsubscribe", channels, block)
end
subscribe_with_timeout(timeout, *channels, &block) click to toggle source
# File lib/redis/subscribe.rb, line 17
def subscribe_with_timeout(timeout, *channels, &block)
  subscription("subscribe", "unsubscribe", channels, block, timeout)
end
unsubscribe(*channels) click to toggle source
# File lib/redis/subscribe.rb, line 29
def unsubscribe(*channels)
  call([:unsubscribe, *channels])
end

Protected Instance Methods

subscription(start, stop, channels, block, timeout = 0) click to toggle source
# File lib/redis/subscribe.rb, line 39
def subscription(start, stop, channels, block, timeout = 0)
  sub = Subscription.new(&block)

  unsubscribed = false

  @client.call_loop([start, *channels], timeout) do |line|
    type, *rest = line
    sub.callbacks[type].call(*rest)
    unsubscribed = type == stop && rest.last == 0
    break if unsubscribed
  end
  # No need to unsubscribe here. The real client closes the connection
  # whenever an exception is raised (see #ensure_connected).
end