Module: Redis::Commands::Lists
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/redis/commands/lists.rb |
Instance Method Summary
-
#blmove(source, destination, where_source, where_destination, timeout: 0) ⇒ nil, String
Remove the first/last element in a list and append/prepend it to another list and return it, or block until one is available.
-
#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.
-
#blpop(*args) ⇒ nil, [String, String]
Remove and get the first element in a list, or block until one is available.
-
#brpop(*args) ⇒ nil, [String, String]
Remove and get the last element in a list, or block until one is available.
-
#brpoplpush(source, destination, timeout: 0) ⇒ nil, String
Pop a value from a list, push it to another list and return it; or block until one is available.
-
#lindex(key, index) ⇒ String
Get an element from a list by its index.
-
#linsert(key, where, pivot, value) ⇒ Integer
Insert an element before or after another element in a list.
-
#llen(key) ⇒ Integer
Get the length of a list.
-
#lmove(source, destination, where_source, where_destination) ⇒ nil, String
Remove the first/last element in a list, append/prepend it to another list and return it.
-
#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.
-
#lpop(key, count = nil) ⇒ nil, ...
Remove and get the first elements in a list.
-
#lpush(key, value) ⇒ Integer
Prepend one or more values to a list, creating the list if it doesn't exist.
-
#lpushx(key, value) ⇒ Integer
Prepend a value to a list, only if the list exists.
-
#lrange(key, start, stop) ⇒ Array<String>
Get a range of elements from a list.
-
#lrem(key, count, value) ⇒ Integer
Remove elements from a list.
-
#lset(key, index, value) ⇒ String
Set the value of an element in a list by its index.
-
#ltrim(key, start, stop) ⇒ String
Trim a list to the specified range.
-
#rpop(key, count = nil) ⇒ nil, ...
Remove and get the last elements in a list.
-
#rpoplpush(source, destination) ⇒ nil, String
Remove the last element in a list, append it to another list and return it.
-
#rpush(key, value) ⇒ Integer
Append one or more values to a list, creating the list if it doesn't exist.
-
#rpushx(key, value) ⇒ Integer
Append a value to a list, only if the list exists.
- #_bpop(cmd, args, &blk) private
- #_normalize_move_wheres(where_source, where_destination) private
Instance Method Details
#_bpop(cmd, args, &blk) (private)
[ GitHub ]# File 'lib/redis/commands/lists.rb', line 306
def _bpop(cmd, args, &blk) timeout = if args.last.is_a?(Hash) = args.pop [: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
#_normalize_move_wheres(where_source, where_destination) (private)
[ GitHub ]# File 'lib/redis/commands/lists.rb', line 323
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
#blmove(source, destination, where_source, where_destination, timeout: 0) ⇒ nil
, String
Remove the first/last element in a list and append/prepend it to another list and return it, or block until one is available.
# File 'lib/redis/commands/lists.rb', line 55
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
#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.
# 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 = [:lmpop, keys.size, *keys, modifier] args << "COUNT" << Integer(count) if count send_blocking_command(args, timeout) end
#blpop(*args) ⇒ nil
, [String
, String
]
Remove and get the first element in a list, or block until one is available.
# File 'lib/redis/commands/lists.rb', line 150
def blpop(*args) _bpop(:blpop, args) end
#brpop(*args) ⇒ nil
, [String
, String
]
Remove and get the last element in a list, or block until one is available.
# File 'lib/redis/commands/lists.rb', line 166
def brpop(*args) _bpop(:brpop, args) end
#brpoplpush(source, destination, timeout: 0) ⇒ nil
, String
Pop a value from a list, push it to another list and return it; or block until one is available.
# File 'lib/redis/commands/lists.rb', line 181
def brpoplpush(source, destination, timeout: 0) command = [:brpoplpush, source, destination, timeout] send_blocking_command(command, timeout) end
#lindex(key, index) ⇒ String
Get an element from a list by its index.
# File 'lib/redis/commands/lists.rb', line 245
def lindex(key, index) send_command([:lindex, key, Integer(index)]) end
#linsert(key, where, pivot, value) ⇒ Integer
Insert an element before or after another element in a list.
# File 'lib/redis/commands/lists.rb', line 257
def linsert(key, where, pivot, value) send_command([:linsert, key, where, pivot, value]) end
#llen(key) ⇒ Integer
Get the length of a list.
# File 'lib/redis/commands/lists.rb', line 10
def llen(key) send_command([:llen, key]) end
#lmove(source, destination, where_source, where_destination) ⇒ nil
, String
This command comes in place of the now deprecated RPOPLPUSH. Doing LMOVE RIGHT LEFT is equivalent.
Remove the first/last element in a list, append/prepend it to another list and return it.
# File 'lib/redis/commands/lists.rb', line 27
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
#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.
# 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
#lpop(key, count = nil) ⇒ nil
, ...
Remove and get the first elements in a list.
# File 'lib/redis/commands/lists.rb', line 103
def lpop(key, count = nil) command = [:lpop, key] command << Integer(count) if count send_command(command) end
#lpush(key, value) ⇒ Integer
Prepend one or more values to a list, creating the list if it doesn't exist
# File 'lib/redis/commands/lists.rb', line 67
def lpush(key, value) send_command([:lpush, key, value]) end
#lpushx(key, value) ⇒ Integer
Prepend a value to a list, only if the list exists.
# File 'lib/redis/commands/lists.rb', line 76
def lpushx(key, value) send_command([:lpushx, key, value]) end
#lrange(key, start, stop) ⇒ Array
<String
>
Get a range of elements from a list.
# File 'lib/redis/commands/lists.rb', line 267
def lrange(key, start, stop) send_command([:lrange, key, Integer(start), Integer(stop)]) end
#lrem(key, count, value) ⇒ Integer
Remove elements from a list.
# File 'lib/redis/commands/lists.rb', line 280
def lrem(key, count, value) send_command([:lrem, key, Integer(count), value]) end
#lset(key, index, value) ⇒ String
Set the value of an element in a list by its index.
# File 'lib/redis/commands/lists.rb', line 290
def lset(key, index, value) send_command([:lset, key, Integer(index), value]) end
#ltrim(key, start, stop) ⇒ String
Trim a list to the specified range.
# File 'lib/redis/commands/lists.rb', line 300
def ltrim(key, start, stop) send_command([:ltrim, key, Integer(start), Integer(stop)]) end
#rpop(key, count = nil) ⇒ nil
, ...
Remove and get the last elements in a list.
# File 'lib/redis/commands/lists.rb', line 114
def rpop(key, count = nil) command = [:rpop, key] command << Integer(count) if count send_command(command) end
#rpoplpush(source, destination) ⇒ nil
, String
Remove the last element in a list, append it to another list and return it.
# File 'lib/redis/commands/lists.rb', line 125
def rpoplpush(source, destination) send_command([:rpoplpush, source, destination]) end
#rpush(key, value) ⇒ Integer
Append one or more values to a list, creating the list if it doesn't exist
# File 'lib/redis/commands/lists.rb', line 85
def rpush(key, value) send_command([:rpush, key, value]) end
#rpushx(key, value) ⇒ Integer
Append a value to a list, only if the list exists.
# File 'lib/redis/commands/lists.rb', line 94
def rpushx(key, value) send_command([:rpushx, key, value]) end