module Protocol::Redis::Methods::Lists

Public Instance Methods

blpop(*keys, timeout: 0) click to toggle source

Remove and get the first element in a list, or block until one is available. O(1). @see redis.io/commands/blpop @param key [Key] @param timeout [Integer]

# File lib/protocol/redis/methods/lists.rb, line 32
def blpop(*keys, timeout: 0)
        call('BLPOP', *keys, timeout)
end
brpop(*keys, timeout: 0) click to toggle source

Remove and get the last element in a list, or block until one is available. O(1). @see redis.io/commands/brpop @param key [Key] @param timeout [Integer]

# File lib/protocol/redis/methods/lists.rb, line 40
def brpop(*keys, timeout: 0)
        call('BRPOP', *keys, timeout)
end
brpoplpush(source, destination, timeout) click to toggle source

Pop an element from a list, push it to another list and return it; or block until one is available. O(1). @see redis.io/commands/brpoplpush @param source [Key] @param destination [Key] @param timeout [Integer]

# File lib/protocol/redis/methods/lists.rb, line 49
def brpoplpush(source, destination, timeout)
        call('BRPOPLPUSH', source, destination, timeout)
end
lindex(key, index) click to toggle source

Get an element from a list by its index. O(N) where N is the number of elements to traverse to get to the element at index. This makes asking for the first or the last element of the list O(1). @see redis.io/commands/lindex @param key [Key] @param index [Integer]

# File lib/protocol/redis/methods/lists.rb, line 57
def lindex(key, index)
        call('LINDEX', key, index)
end
linsert(key, position=:before, index, value) click to toggle source

Insert an element before or after another element in a list. O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N). @see redis.io/commands/linsert @param key [Key] @param where [Enum] @param pivot [String] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 67
def linsert(key, position=:before, index, value)
        if position == :before
                offset = 'BEFORE'
        else
                offset = 'AFTER'
        end
        
        call('LINSERT', key, offset, index, value)
end
llen(key) click to toggle source

Get the length of a list. O(1). @see redis.io/commands/llen @param key [Key]

# File lib/protocol/redis/methods/lists.rb, line 80
def llen(key)
        call('LLEN', key)
end
lpop(key) click to toggle source

Remove and get the first element in a list. O(1). @see redis.io/commands/lpop @param key [Key]

# File lib/protocol/redis/methods/lists.rb, line 87
def lpop(key)
        call('LPOP', key)
end
lpush(key, value, *values) click to toggle source

Prepend one or multiple elements to a list. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. @see redis.io/commands/lpush @param key [Key] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 95
def lpush(key, value, *values)
        case value
        when Array
                values = value
        else
                values = [value] + values
        end
        
        call('LPUSH', key, *values)
end
lpushx(key, value) click to toggle source

Prepend an element to a list, only if the list exists. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. @see redis.io/commands/lpushx @param key [Key] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 110
def lpushx(key, value)
        call('LPUSHX', key, value)
end
lrange(key, start, stop) click to toggle source

Get a range of elements from a list. O(S+N) where S is the distance of start offset from HEAD for small lists, from nearest end (HEAD or TAIL) for large lists; and N is the number of elements in the specified range. @see redis.io/commands/lrange @param key [Key] @param start [Integer] @param stop [Integer]

# File lib/protocol/redis/methods/lists.rb, line 119
def lrange(key, start, stop)
        call('LRANGE', key, start, stop)
end
lrem(key, count, value) click to toggle source

Remove elements from a list. O(N+M) where N is the length of the list and M is the number of elements removed. @see redis.io/commands/lrem @param key [Key] @param count [Integer] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 128
def lrem(key, count, value)
        call('LREM', key, count, value)
end
lset(key, index, values) click to toggle source

Set the value of an element in a list by its index. O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1). @see redis.io/commands/lset @param key [Key] @param index [Integer] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 137
def lset(key, index, values)
        call('LSET', key, index, values)
end
ltrim(key, start, stop) click to toggle source

Trim a list to the specified range. O(N) where N is the number of elements to be removed by the operation. @see redis.io/commands/ltrim @param key [Key] @param start [Integer] @param stop [Integer]

# File lib/protocol/redis/methods/lists.rb, line 146
def ltrim(key, start, stop)
        call('LTRIM', key, start, stop)
end
rpop(key) click to toggle source

Remove and get the last element in a list. O(1). @see redis.io/commands/rpop @param key [Key]

# File lib/protocol/redis/methods/lists.rb, line 153
def rpop(key)
        call('RPOP', key)
end
rpoplpush(source, destination=nil) click to toggle source

Remove the last element in a list, prepend it to another list and return it. O(1). @see redis.io/commands/rpoplpush @param source [Key] @param destination [Key]

# File lib/protocol/redis/methods/lists.rb, line 161
def rpoplpush(source, destination=nil)
        destination = source if destination.nil?
        
        call('RPOPLPUSH', source, destination)
end
rpush(key, value, *values) click to toggle source

Append one or multiple elements to a list. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. @see redis.io/commands/rpush @param key [Key] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 171
def rpush(key, value, *values)
        case value
        when Array
                values = value
        else
                values = [value] + values
        end
        
        call('RPUSH', key, *values)
end
rpushx(key, value) click to toggle source

Append an element to a list, only if the list exists. O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments. @see redis.io/commands/rpushx @param key [Key] @param element [String]

# File lib/protocol/redis/methods/lists.rb, line 186
def rpushx(key, value)
        call('RPUSHX', key, value)
end