Module: Oxblood::Commands::Lists

Included in:
Oxblood::Commands
Defined in:
lib/oxblood/commands/lists.rb

Instance Method Summary collapse

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

Parameters:

  • keys (String, Array<String>)
  • timeout (Integer)

    in seconds

Returns:

  • (nil)

    when no element could be popped and the timeout expired

  • ([String, String])

    a two-element multi-bulk with the first element being the name of the key where an element was popped and

See Also:


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

Parameters:

  • keys (String, Array<String>)
  • timeout (Integer)

    in seconds

Returns:

  • (nil)

    when no element could be popped and the timeout expired

  • ([String, String])

    a two-element multi-bulk with the first element being the name of the key where an element was popped and

See Also:


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

Parameters:

  • source (String)
  • destination (String)

Returns:

  • (nil)

    when no element could be popped and the timeout expired

  • (String)

    the element being popped and pushed

See Also:


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

Parameters:

  • key (String)
  • index (Integer)

    zero-based of element in the list

Returns:

  • (String)

    the requested element, or nil when index is out of range.

See Also:


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

Parameters:

  • key (String)
  • place (Symbol)

    could be :before or :after

  • pivot (String)

    reference value

  • value (String)

    to insert

Returns:

  • (Integer)

    the length of the list after the insert operation,

See Also:


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

Parameters:

  • key (String)

Returns:

  • (Integer)

    the length of the list at key

  • (RError)

    if the value stored at key is not a list

See Also:


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

Parameters:

  • key (String)

Returns:

  • (String, nil)

    the value of the first element, or nil when key does not exist.

See Also:


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

Parameters:

  • key (String)
  • values (Array)

    to prepend

Returns:

  • (Integer)

    the length of the list after the push operations

See Also:


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

Parameters:

  • key (String)
  • value (String)

Returns:

  • (Integer)

    the length of the list after the push operation

See Also:


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

Parameters:

  • key (String)
  • start (Integer)

    index

  • stop (Integer)

    index

Returns:

  • (Array)

    list of elements in the specified range

See Also:


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

Parameters:

  • key (String)
  • count (Integer)

    (please look into official docs for more info)

  • value (String)

    to remove

Returns:

  • (Integer)

    the number of removed elements

See Also:


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

Parameters:

  • key (String)
  • index (Integer)
  • value (String)

Returns:

  • (String)

    'OK'

  • (RError)

    if index is out of range

See Also:


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

Parameters:

  • key (String)
  • start (Integer)
  • stop (Integer)

Returns:

  • (String)

    'OK'

See Also:


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

Parameters:

  • key (String)

Returns:

  • (String, nil)

    the value of the last element, or nil when key does not exist

See Also:


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

Parameters:

  • source (String)
  • destination (String)

Returns:

  • (String, nil)

    the element being popped and pushed, or nil when source does not exist

See Also:


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

Parameters:

  • key (String)
  • values (Array)

    to add

Returns:

  • (Integer)

    the length of the list after the push operation

  • (RError)

    if key holds a value that is not a list

See Also:


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

Parameters:

  • key (String)
  • value (String)

Returns:

  • (Integer)

    the length of the list after the push operation

See Also:


207
208
209
# File 'lib/oxblood/commands/lists.rb', line 207

def rpushx(key, value)
  run(:RPUSHX, key, value)
end