Method: Redis::Commands::Lists#lmpop

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

#lmpop(*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.

Examples:

Popping a element

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

With count option

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

Returns:

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

    list of popped elements or nil

Raises:

  • (ArgumentError)


231
232
233
234
235
236
237
238
# File 'lib/redis/commands/lists.rb', line 231

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

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

  send_command(args)
end