Method: Redis::Commands::Lists#blmpop

Defined in:
lib/redis/commands/lists.rb

#blmpop(timeout, *keys, modifier: "LEFT", count: nil) ⇒ Array<String, Array<String, Float>>

Pops one or more elements from the first non-empty list key from the list of provided key names. If lists are empty, blocks until timeout has passed.

Examples:

Popping a element

redis.blmpop(1.0, 'list')
#=> ['list', ['a']]

With count option

redis.blmpop(1.0, 'list', count: 2)
#=> ['list', ['a', 'b']]

Returns:

  • (Array<String, Array<String, Float>>)

    list of popped elements or nil

Raises:

  • (ArgumentError)


205
206
207
208
209
210
211
212
# File 'lib/redis/commands/lists.rb', line 205

def blmpop(timeout, *keys, modifier: "LEFT", count: nil)
  raise ArgumentError, "Pick either LEFT or RIGHT" unless modifier == "LEFT" || modifier == "RIGHT"

  args = [:blmpop, timeout, keys.size, *keys, modifier]
  args << "COUNT" << Integer(count) if count

  send_blocking_command(args, timeout)
end