Method: Redis#blpop

Defined in:
lib/redis.rb

#blpop(keys, options = {}) ⇒ nil, [String, String]

Remove and get the first element in a list, or block until one is available.

Examples:

With timeout

list, element = redis.blpop("list", :timeout => 5)
  # => nil on timeout
  # => ["list", "element"] on success

Without timeout

list, element = redis.blpop("list")
  # => ["list", "element"]

Blocking pop on multiple lists

list, element = redis.blpop(["list", "another_list"])
  # => ["list", "element"]

Parameters:

  • keys (String, Array<String>)

    one or more keys to perform the blocking pop on

  • options (Hash) (defaults to: {})
    • :timeout => Fixnum: timeout in seconds, defaults to no timeout

Returns:

  • (nil, [String, String])
    • nil when the operation timed out
    • tuple of the list that was popped from and element was popped otherwise


534
535
536
537
538
539
540
# File 'lib/redis.rb', line 534

def blpop(keys, options = {})
  timeout = options[:timeout] || 0

  synchronize do
    @client.call_without_timeout [:blpop, keys, timeout]
  end
end