module Rubbis::State::BlockingCommands

Public Instance Methods

brpop(key, timeout, client) click to toggle source
# File lib/rubbis/state.rb, line 376
def brpop(key, timeout, client)
        list = get(key)
        list ||= data[key] = []

        action = ->{ rpop(key) }

        if llen(key) == 0
                list_watches[key] ||= []
                list_watches[key] << [action, client]
                :block
        else
                action.call
        end
end
brpoplpush(pop_key, push_key, timeout, client) click to toggle source
# File lib/rubbis/state.rb, line 363
def brpoplpush(pop_key, push_key, timeout, client)

        action = ->{ rpoplpush(pop_key, push_key) }

        if llen(pop_key) == 0
                list_watches[pop_key] ||= []
                list_watches[pop_key] << [action, client]
                :block
        else
                action.call
        end
end
psubscribe(channel, client) click to toggle source
# File lib/rubbis/state.rb, line 349
def psubscribe(channel, client)
        psubscribers[channel] << client
        pchannels[client] << channel

        ['psubscribe', channel, channel_count(client)]
end
punsubscribe(channel, client) click to toggle source
# File lib/rubbis/state.rb, line 356
def punsubscribe(channel, client)
        psubscribers[channel].delete client
        pchannels[client].delete channel

        ['punsubscribe', channel, channel_count(client)]
end
subscribe(channel, client) click to toggle source
# File lib/rubbis/state.rb, line 335
def subscribe(channel, client)
        subscribers[channel] << client
        channels[client] << channel

        ['subscribe', channel, channel_count(client)]
end
unsubscribe(channel, client) click to toggle source
# File lib/rubbis/state.rb, line 342
def unsubscribe(channel, client)
        subscribers[channel].delete client
        channels[client].delete channel

        ['unsubscribe', channel, channel_count(client)]
end