Protocol::Redis SourceProtocolRedisMethodsLists

module Lists

Definitions

def blpop(*keys, timeout: 0)

Remove and get the first element in a list, or block until one is available. O(1).

Implementation

def blpop(*keys, timeout: 0)
	call('BLPOP', *keys, timeout)
end

def brpop(*keys, timeout: 0)

Remove and get the last element in a list, or block until one is available. O(1).

Implementation

def brpop(*keys, timeout: 0)
	call('BRPOP', *keys, timeout)
end

def brpoplpush(source, destination, timeout)

Pop an element from a list, push it to another list and return it; or block until one is available. O(1).

Implementation

def brpoplpush(source, destination, timeout)
	call('BRPOPLPUSH', source, destination, timeout)
end

def lindex(key, index)

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).

Implementation

def lindex(key, index)
	call('LINDEX', key, index)
end

def linsert(key, position=:before, index, value)

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).

Implementation

def linsert(key, position=:before, index, value)
	if position == :before
		offset = 'BEFORE'
	else
		offset = 'AFTER'
	end
	
	call('LINSERT', key, offset, index, value)
end

def llen(key)

Get the length of a list. O(1).

Implementation

def llen(key)
	call('LLEN', key)
end

def lpop(key)

Remove and get the first element in a list. O(1).

Implementation

def lpop(key)
	call('LPOP', key)
end

def lpush(key, value, *values)

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.

Implementation

def lpush(key, value, *values)
	case value
	when Array
		values = value
	else
		values = [value] + values
	end
	
	call('LPUSH', key, *values)
end

def lpushx(key, value)

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.

Implementation

def lpushx(key, value)
	call('LPUSHX', key, value)
end

def lrange(key, start, stop)

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.

Implementation

def lrange(key, start, stop)
	call('LRANGE', key, start, stop)
end

def lrem(key, count, value)

Remove elements from a list. O(N+M) where N is the length of the list and M is the number of elements removed.

Implementation

def lrem(key, count, value)
	call('LREM', key, count, value)
end

def lset(key, index, values)

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).

Implementation

def lset(key, index, values)
	call('LSET', key, index, values)
end

def ltrim(key, start, stop)

Trim a list to the specified range. O(N) where N is the number of elements to be removed by the operation.

Implementation

def ltrim(key, start, stop)
	call('LTRIM', key, start, stop)
end

def rpop(key)

Remove and get the last element in a list. O(1).

Implementation

def rpop(key)
	call('RPOP', key)
end

def rpoplpush(source, destination=nil)

Remove the last element in a list, prepend it to another list and return it. O(1).

Implementation

def rpoplpush(source, destination=nil)
	destination = source if destination.nil?
	
	call('RPOPLPUSH', source, destination)
end

def rpush(key, value, *values)

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.

Implementation

def rpush(key, value, *values)
	case value
	when Array
		values = value
	else
		values = [value] + values
	end
	
	call('RPUSH', key, *values)
end

def rpushx(key, value)

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.

Implementation

def rpushx(key, value)
	call('RPUSHX', key, value)
end