Module: Redis::Commands::Lists
- Included in:
- Redis::Commands
- Defined in:
- lib/redis/commands/lists.rb
Instance Method Summary collapse
-
#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.
-
#blmovem(source, destination, where_source, where_destination, timeout: 0, count: nil, exactly: nil, order: nil) ⇒ nil, Array<String>
Remove multiple elements from the head/tail of a list, append/prepend them to another list and return them; or block until the request can be satisfied or the timeout expires.
-
#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.
-
#lmovem(source, destination, where_source, where_destination, count: nil, exactly: nil, order: nil) ⇒ nil, Array<String>
Remove multiple elements from the head/tail of a list, append/prepend them to another list and return them.
-
#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.
Instance Method Details
#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.
133 134 135 136 137 138 |
# File 'lib/redis/commands/lists.rb', line 133 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 |
#blmovem(source, destination, where_source, where_destination, timeout: 0, count: nil, exactly: nil, order: nil) ⇒ nil, Array<String>
Remove multiple elements from the head/tail of a list, append/prepend them to another list and return them; or block until the request can be satisfied or the timeout expires.
- when
'OBO'- push each element as popped, so the moved block order is reversed - when
'BULK'- preserve the original relative order of the moved elements
101 102 103 104 105 106 107 108 109 |
# File 'lib/redis/commands/lists.rb', line 101 def blmovem(source, destination, where_source, where_destination, timeout: 0, count: nil, exactly: nil, order: nil) where_source, where_destination = _normalize_move_wheres(where_source, where_destination) command = [:blmovem, source, destination, where_source, where_destination, timeout] command.concat(_movem_amount_args(count, exactly, order)) 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.
283 284 285 286 287 288 289 290 |
# File 'lib/redis/commands/lists.rb', line 283 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 |
#blpop(*args) ⇒ nil, [String, String]
Remove and get the first element in a list, or block until one is available.
228 229 230 |
# File 'lib/redis/commands/lists.rb', line 228 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.
244 245 246 |
# File 'lib/redis/commands/lists.rb', line 244 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.
259 260 261 262 |
# File 'lib/redis/commands/lists.rb', line 259 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.
323 324 325 |
# File 'lib/redis/commands/lists.rb', line 323 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.
335 336 337 |
# File 'lib/redis/commands/lists.rb', line 335 def linsert(key, where, pivot, value) send_command([:linsert, key, where, pivot, value]) end |
#llen(key) ⇒ Integer
Get the length of a list.
10 11 12 |
# 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.
27 28 29 30 31 |
# 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 |
#lmovem(source, destination, where_source, where_destination, count: nil, exactly: nil, order: nil) ⇒ nil, Array<String>
Remove multiple elements from the head/tail of a list, append/prepend them to another list and return them.
- when
'OBO'- push each element as popped, so the moved block order is reversed - when
'BULK'- preserve the original relative order of the moved elements
62 63 64 65 66 67 68 69 |
# File 'lib/redis/commands/lists.rb', line 62 def lmovem(source, destination, where_source, where_destination, count: nil, exactly: nil, order: nil) where_source, where_destination = _normalize_move_wheres(where_source, where_destination) args = [:lmovem, source, destination, where_source, where_destination] args.concat(_movem_amount_args(count, exactly, order)) send_command(args) 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.
309 310 311 312 313 314 315 316 |
# File 'lib/redis/commands/lists.rb', line 309 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.
181 182 183 184 185 |
# File 'lib/redis/commands/lists.rb', line 181 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
145 146 147 |
# File 'lib/redis/commands/lists.rb', line 145 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.
154 155 156 |
# File 'lib/redis/commands/lists.rb', line 154 def lpushx(key, value) send_command([:lpushx, key, value]) end |
#lrange(key, start, stop) ⇒ Array<String>
Get a range of elements from a list.
345 346 347 |
# File 'lib/redis/commands/lists.rb', line 345 def lrange(key, start, stop) send_command([:lrange, key, Integer(start), Integer(stop)]) end |
#lrem(key, count, value) ⇒ Integer
Remove elements from a list.
358 359 360 |
# File 'lib/redis/commands/lists.rb', line 358 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.
368 369 370 |
# File 'lib/redis/commands/lists.rb', line 368 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.
378 379 380 |
# File 'lib/redis/commands/lists.rb', line 378 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.
192 193 194 195 196 |
# File 'lib/redis/commands/lists.rb', line 192 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.
203 204 205 |
# File 'lib/redis/commands/lists.rb', line 203 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
163 164 165 |
# File 'lib/redis/commands/lists.rb', line 163 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.
172 173 174 |
# File 'lib/redis/commands/lists.rb', line 172 def rpushx(key, value) send_command([:rpushx, key, value]) end |