module RedisCluster::Function::List
List
implement redis lists commands. There will be some adjustment for cluster. see redis.io/commands#list. Most of the code are copied from github.com/redis/redis-rb/blob/master/lib/redis.rb.
SETTER = [:linsert, :lpop, :lpush, :lpushx, :lrem, :lset, :ltrim, :rpop, :rpush, :rpushx] GETTER = [:lindex, :llen, :lrange]
Public Instance Methods
Get an element from a list by its index.
@param [String] key @param [Fixnum] index @return [String]
# File lib/redis_cluster/function/list.rb, line 79 def lindex(key, index) call(key, [:lindex, key, index], read: true) end
Insert an element before or after another element in a list.
@param [String] key @param [String, Symbol] where `BEFORE` or `AFTER` @param [String] pivot reference element @param [String] value @return [Fixnum] length of the list after the insert operation, or `-1`
when the element `pivot` was not found
# File lib/redis_cluster/function/list.rb, line 91 def linsert(key, where, pivot, value) call(key, [:linsert, key, where, pivot, value]) end
Get the length of a list.
@param [String] key @return [Fixnum]
# File lib/redis_cluster/function/list.rb, line 18 def llen(key) call(key, [:llen, key], read: true) end
Remove and get the first element in a list.
@param [String] key @return [String]
# File lib/redis_cluster/function/list.rb, line 62 def lpop(key) call(key, [:lpop, key]) end
Prepend one or more values to a list, creating the list if it doesn't exist
@param [String] key @param [String, Array] value string value, or array of string values to push @return [Fixnum] the length of the list after the push operation
# File lib/redis_cluster/function/list.rb, line 27 def lpush(key, value) call(key, [:lpush, key, value]) end
Prepend a value to a list, only if the list exists.
@param [String] key @param [String] value @return [Fixnum] the length of the list after the push operation
# File lib/redis_cluster/function/list.rb, line 36 def lpushx(key, value) call(key, [:lpushx, key, value]) end
Get a range of elements from a list.
@param [String] key @param [Fixnum] start start index @param [Fixnum] stop stop index @return [Array<String>]
# File lib/redis_cluster/function/list.rb, line 101 def lrange(key, start, stop) call(key, [:lrange, key, start, stop], read: true) end
Remove elements from a list.
@param [String] key @param [Fixnum] count number of elements to remove. Use a positive
value to remove the first `count` occurrences of `value`. A negative value to remove the last `count` occurrences of `value`. Or zero, to remove all occurrences of `value` from the list.
@param [String] value @return [Fixnum] the number of removed elements
# File lib/redis_cluster/function/list.rb, line 114 def lrem(key, count, value) call(key, [:lrem, key, count, value]) end
Set
the value of an element in a list by its index.
@param [String] key @param [Fixnum] index @param [String] value @return [String] `OK`
# File lib/redis_cluster/function/list.rb, line 124 def lset(key, index, value) call(key, [:lset, key, index, value]) end
Trim a list to the specified range.
@param [String] key @param [Fixnum] start start index @param [Fixnum] stop stop index @return [String] `OK`
# File lib/redis_cluster/function/list.rb, line 134 def ltrim(key, start, stop) call(key, [:ltrim, key, start, stop]) end
Remove and get the last element in a list.
@param [String] key @return [String]
# File lib/redis_cluster/function/list.rb, line 70 def rpop(key) call(key, [:rpop, key]) end
Append one or more values to a list, creating the list if it doesn't exist
@param [String] key @param [String] value @return [Fixnum] the length of the list after the push operation
# File lib/redis_cluster/function/list.rb, line 45 def rpush(key, value) call(key, [:rpush, key, value]) end
Append a value to a list, only if the list exists.
@param [String] key @param [String] value @return [Fixnum] the length of the list after the push operation
# File lib/redis_cluster/function/list.rb, line 54 def rpushx(key, value) call(key, [:rpushx, key, value]) end