module Redis::Commands::Pubsub

def psubscribe(*channels, &block)

Listen for messages published to channels matching the given patterns.
def psubscribe(*channels, &block)
  synchronize do |_client|
    _subscription(:psubscribe, 0, channels, block)
  end
end

def psubscribe_with_timeout(timeout, *channels, &block)

Throw a timeout error if there is no messages for a timeout period.
Listen for messages published to channels matching the given patterns.
def psubscribe_with_timeout(timeout, *channels, &block)
  synchronize do |_client|
    _subscription(:psubscribe_with_timeout, timeout, channels, block)
  end
end

def publish(channel, message)

Post a message to a channel.
def publish(channel, message)
  send_command([:publish, channel, message])
end

def pubsub(subcommand, *args)

Possible subcommands: channels, numsub, numpat.
Inspect the state of the Pub/Sub subsystem.
def pubsub(subcommand, *args)
  send_command([:pubsub, subcommand] + args)
end

def punsubscribe(*channels)

Stop listening for messages posted to channels matching the given patterns.
def punsubscribe(*channels)
  synchronize do |client|
    raise "Can't unsubscribe if not subscribed." unless subscribed?
    client.punsubscribe(*channels)
  end
end

def subscribe(*channels, &block)

Listen for messages published to the given channels.
def subscribe(*channels, &block)
  synchronize do |_client|
    _subscription(:subscribe, 0, channels, block)
  end
end

def subscribe_with_timeout(timeout, *channels, &block)

if there is no messages for a timeout period.
Listen for messages published to the given channels. Throw a timeout error
def subscribe_with_timeout(timeout, *channels, &block)
  synchronize do |_client|
    _subscription(:subscribe_with_timeout, timeout, channels, block)
  end
end

def subscribed?

def subscribed?
  synchronize do |client|
    client.is_a? SubscribedClient
  end
end

def unsubscribe(*channels)

Stop listening for messages posted to the given channels.
def unsubscribe(*channels)
  synchronize do |client|
    raise "Can't unsubscribe if not subscribed." unless subscribed?
    client.unsubscribe(*channels)
  end
end