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] elsif args.last.respond_to?(:to_int) last_arg = args.pop ::Redis.deprecate!( "Passing the timeout as a positional argument is deprecated, it should be passed as a keyword argument:\n" \ " redis.#{cmd}(#{args.map(&:inspect).join(', ')}, timeout: #{last_arg.to_int})" \ "(called from: #{caller(2, 1).first})" ) last_arg.to_int end timeout ||= 0 keys = args.flatten command = [cmd, keys, 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 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, deprecated_timeout = 0, timeout: deprecated_timeout)
-
(nil, String)
-
Parameters:
-
options
(Hash
) -- -
destination
(String
) -- destination key -
source
(String
) -- source key
def brpoplpush(source, destination, deprecated_timeout = 0, timeout: deprecated_timeout) 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, 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 lpop(key, count = 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 << 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, start, 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, 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, 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, start, stop]) end
def rpop(key, count = 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 << 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