Module: Oxblood::Commands::Lists
- Included in:
- Oxblood::Commands
- Defined in:
- lib/oxblood/commands/lists.rb
Instance Method Summary collapse
-
#blpop(*keys, timeout) ⇒ nil, [String, String]
Remove and get the first element in a list, or block until one is available the second element being the value of the popped element.
-
#brpop(*keys, timeout) ⇒ nil, [String, String]
Remove and get the last element in a list, or block until one is available the second element being the value of the popped element.
-
#brpoplpush(source, destination, timeout) ⇒ 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, place, pivot, value) ⇒ Integer
Insert an element before or after another element in a list or -1 when the value pivot was not found.
-
#llen(key) ⇒ Integer, RError
Get the length of a list.
-
#lpop(key) ⇒ String?
Remove and get the first element in a list.
-
#lpush(key, *values) ⇒ Integer
Prepend one or multiple values to a list.
-
#lpushx(key, value) ⇒ Integer
Prepend a value to a list, only if the list exists.
-
#lrange(key, start, stop) ⇒ Array
Get a range of elements from a list.
-
#lrem(key, count, value) ⇒ Integer
Remove elements from a list.
-
#lset(key, index, value) ⇒ String, RError
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) ⇒ String?
Remove and get the last element in a list.
-
#rpoplpush(source, destination) ⇒ String?
Remove the last element in a list, prepend it to another list and return.
-
#rpush(key, *values) ⇒ Integer, RError
Append one or multiple values to a list.
-
#rpushx(key, value) ⇒ Integer
Append a value to a list, only if the list exists.
Instance Method Details
#blpop(*keys, timeout) ⇒ nil, [String, String]
Remove and get the first element in a list, or block until one is available
the second element being the value of the popped element
15 16 17 |
# File 'lib/oxblood/commands/lists.rb', line 15 def blpop(*keys, timeout) blocking_pop(:BLPOP, keys, timeout) end |
#brpop(*keys, timeout) ⇒ nil, [String, String]
Remove and get the last element in a list, or block until one is available
the second element being the value of the popped element
30 31 32 |
# File 'lib/oxblood/commands/lists.rb', line 30 def brpop(*keys, timeout) blocking_pop(:BRPOP, keys, timeout) end |
#brpoplpush(source, destination, timeout) ⇒ nil, String
Pop a value from a list, push it to another list and return it; or block until one is available
43 44 45 |
# File 'lib/oxblood/commands/lists.rb', line 43 def brpoplpush(source, destination, timeout) blocking_pop(:BRPOPLPUSH, [source, destination], timeout) end |
#lindex(key, index) ⇒ String
Get an element from a list by its index
54 55 56 |
# File 'lib/oxblood/commands/lists.rb', line 54 def lindex(key, index) run(:LINDEX, key, index) end |
#linsert(key, place, pivot, value) ⇒ Integer
Insert an element before or after another element in a list or -1 when the value pivot was not found
68 69 70 |
# File 'lib/oxblood/commands/lists.rb', line 68 def linsert(key, place, pivot, value) run(:LINSERT, key, place, pivot, value) end |
#llen(key) ⇒ Integer, RError
Get the length of a list
79 80 81 |
# File 'lib/oxblood/commands/lists.rb', line 79 def llen(key) run(:LLEN, key) end |
#lpop(key) ⇒ String?
Remove and get the first element in a list
90 91 92 |
# File 'lib/oxblood/commands/lists.rb', line 90 def lpop(key) run(:LPOP, key) end |
#lpush(key, *values) ⇒ Integer
Prepend one or multiple values to a list
101 102 103 |
# File 'lib/oxblood/commands/lists.rb', line 101 def lpush(key, *values) run(*values.unshift(:LPUSH, key)) end |
#lpushx(key, value) ⇒ Integer
Prepend a value to a list, only if the list exists
112 113 114 |
# File 'lib/oxblood/commands/lists.rb', line 112 def lpushx(key, value) run(:LPUSHX, key, value) end |
#lrange(key, start, stop) ⇒ Array
Get a range of elements from a list
124 125 126 |
# File 'lib/oxblood/commands/lists.rb', line 124 def lrange(key, start, stop) run(:LRANGE, key, start, stop) end |
#lrem(key, count, value) ⇒ Integer
Remove elements from a list
136 137 138 |
# File 'lib/oxblood/commands/lists.rb', line 136 def lrem(key, count, value) run(:LREM, key, count, value) end |
#lset(key, index, value) ⇒ String, RError
Set the value of an element in a list by its index
149 150 151 |
# File 'lib/oxblood/commands/lists.rb', line 149 def lset(key, index, value) run(:LSET, key, index, value) end |
#ltrim(key, start, stop) ⇒ String
Trim a list to the specified range
161 162 163 |
# File 'lib/oxblood/commands/lists.rb', line 161 def ltrim(key, start, stop) run(:LTRIM, key, start, stop) end |
#rpop(key) ⇒ String?
Remove and get the last element in a list
172 173 174 |
# File 'lib/oxblood/commands/lists.rb', line 172 def rpop(key) run(:RPOP, key) end |
#rpoplpush(source, destination) ⇒ String?
Remove the last element in a list, prepend it to another list and return
184 185 186 |
# File 'lib/oxblood/commands/lists.rb', line 184 def rpoplpush(source, destination) run(:RPOPLPUSH, source, destination) end |
#rpush(key, *values) ⇒ Integer, RError
Append one or multiple values to a list
196 197 198 |
# File 'lib/oxblood/commands/lists.rb', line 196 def rpush(key, *values) run(*values.unshift(:RPUSH, key)) end |
#rpushx(key, value) ⇒ Integer
Append a value to a list, only if the list exists
207 208 209 |
# File 'lib/oxblood/commands/lists.rb', line 207 def rpushx(key, value) run(:RPUSHX, key, value) end |