module Redis::Commands::Lists
def _bpop(cmd, args, &blk)
def _bpop(cmd, args, &blk) timeout = if args.last.is_a?(Hash) options = args.pop options[:timeout] end timeout ||= 0 unless timeout.is_a?(Integer) || timeout.is_a?(Float) raise ArgumentError, "timeout must be an Integer or Float, got: #{timeout.class}" end args.flatten!(1) command = [cmd].concat(args) command << timeout send_blocking_command(command, timeout, &blk) end
def _normalize_move_wheres(where_source, where_destination)
def _normalize_move_wheres(where_source, where_destination) where_source = where_source.to_s.upcase where_destination = where_destination.to_s.upcase if where_source != "LEFT" && where_source != "RIGHT" raise ArgumentError, "where_source must be 'LEFT' or 'RIGHT'" end if where_destination != "LEFT" && where_destination != "RIGHT" raise ArgumentError, "where_destination must be 'LEFT' or 'RIGHT'" end [where_source, where_destination] end
def blmove(source, destination, where_source, where_destination, timeout: 0)
-
(nil, String)
- the element, or nil when the source key does not exist or the timeout expired
Parameters:
-
options
(Hash
) -- -
where_destination
(String, Symbol
) -- where to push the element to the source list -
where_source
(String, Symbol
) -- from where to remove the element from the source list -
destination
(String
) -- destination key -
source
(String
) -- source key
Other tags:
- Example: Without timeout -
Example: With timeout -
def blmove(source, destination, where_source, where_destination, timeout: 0) where_source, where_destination = _normalize_move_wheres(where_source, where_destination) command = [:blmove, source, destination, where_source, where_destination, timeout] send_blocking_command(command, timeout) end
def blmpop(timeout, *keys, modifier: "LEFT", count: nil)
-
(Array
- list of popped elements or nil>)
Other tags:
- Example: With count option -
Example: Popping a element -
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
def blpop(*args)
-
(nil, [String, String])
-
Parameters:
-
options
(Hash
) -- -
keys
(String, Array
) -- one or more keys to perform the
Other tags:
- Example: Blocking pop on multiple lists -
Example: Without timeout -
Example: With timeout -
def blpop(*args) _bpop(:blpop, args) end
def brpop(*args)
- See: #blpop -
Returns:
-
(nil, [String, String])
-
Parameters:
-
options
(Hash
) -- -
keys
(String, Array
) -- one or more keys to perform the
def brpop(*args) _bpop(:brpop, args) end
def brpoplpush(source, destination, timeout: 0)
-
(nil, String)
-
Parameters:
-
options
(Hash
) -- -
destination
(String
) -- destination key -
source
(String
) -- source key
def brpoplpush(source, destination, timeout: 0) command = [:brpoplpush, source, destination, timeout] send_blocking_command(command, timeout) end
def lindex(key, index)
-
(String)
-
Parameters:
-
index
(Integer
) -- -
key
(String
) --
def lindex(key, index) send_command([:lindex, key, Integer(index)]) end
def linsert(key, where, pivot, value)
-
(Integer)
- length of the list after the insert operation, or `-1`
Parameters:
-
value
(String
) -- -
pivot
(String
) -- reference element -
where
(String, Symbol
) -- `BEFORE` or `AFTER` -
key
(String
) --
def linsert(key, where, pivot, value) send_command([:linsert, key, where, pivot, value]) end
def llen(key)
-
(Integer)
-
Parameters:
-
key
(String
) --
def llen(key) send_command([:llen, key]) end
def lmove(source, destination, where_source, where_destination)
- Note: - This command comes in place of the now deprecated RPOPLPUSH.
Returns:
-
(nil, String)
- the element, or nil when the source key does not exist
Parameters:
-
where_destination
(String, Symbol
) -- where to push the element to the source list -
where_source
(String, Symbol
) -- from where to remove the element from the source list -
destination
(String
) -- destination key -
source
(String
) -- source key
def lmove(source, destination, where_source, where_destination) where_source, where_destination = _normalize_move_wheres(where_source, where_destination) send_command([:lmove, source, destination, where_source, where_destination]) end
def lmpop(*keys, modifier: "LEFT", count: nil)
-
(Array
- list of popped elements or nil>)
Other tags:
- Example: With count option -
Example: Popping a element -
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
def lpop(key, count = nil)
-
(nil, String, Array
- the values of the first elements)
Parameters:
-
count
(Integer
) -- number of elements to remove -
key
(String
) --
def lpop(key, count = nil) command = [:lpop, key] command << Integer(count) if count send_command(command) end
def lpush(key, value)
-
(Integer)
- the length of the list after the push operation
Parameters:
-
value
(String, Array
) -- string value, or array of string values to push -
key
(String
) --
def lpush(key, value) send_command([:lpush, key, value]) end
def lpushx(key, value)
-
(Integer)
- the length of the list after the push operation
Parameters:
-
value
(String
) -- -
key
(String
) --
def lpushx(key, value) send_command([:lpushx, key, value]) end
def lrange(key, start, stop)
-
(Array
-)
Parameters:
-
stop
(Integer
) -- stop index -
start
(Integer
) -- start index -
key
(String
) --
def lrange(key, start, stop) send_command([:lrange, key, Integer(start), Integer(stop)]) end
def lrem(key, count, value)
-
(Integer)
- the number of removed elements
Parameters:
-
value
(String
) -- -
count
(Integer
) -- number of elements to remove. Use a positive -
key
(String
) --
def lrem(key, count, value) send_command([:lrem, key, Integer(count), value]) end
def lset(key, index, value)
-
(String)
- `OK`
Parameters:
-
value
(String
) -- -
index
(Integer
) -- -
key
(String
) --
def lset(key, index, value) send_command([:lset, key, Integer(index), value]) end
def ltrim(key, start, stop)
-
(String)
- `OK`
Parameters:
-
stop
(Integer
) -- stop index -
start
(Integer
) -- start index -
key
(String
) --
def ltrim(key, start, stop) send_command([:ltrim, key, Integer(start), Integer(stop)]) end
def rpop(key, count = nil)
-
(nil, String, Array
- the values of the last elements)
Parameters:
-
count
(Integer
) -- number of elements to remove -
key
(String
) --
def rpop(key, count = nil) command = [:rpop, key] command << Integer(count) if count send_command(command) end
def rpoplpush(source, destination)
-
(nil, String)
- the element, or nil when the source key does not exist
Parameters:
-
destination
(String
) -- destination key -
source
(String
) -- source key
def rpoplpush(source, destination) send_command([:rpoplpush, source, destination]) end
def rpush(key, value)
-
(Integer)
- the length of the list after the push operation
Parameters:
-
value
(String, Array
) -- string value, or array of string values to push -
key
(String
) --
def rpush(key, value) send_command([:rpush, key, value]) end
def rpushx(key, value)
-
(Integer)
- the length of the list after the push operation
Parameters:
-
value
(String
) -- -
key
(String
) --
def rpushx(key, value) send_command([:rpushx, key, value]) end