Module: Oxblood::Commands::Strings

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

Instance Method Summary collapse

Instance Method Details

#append(key, value) ⇒ Integer

Append a value to a key

Parameters:

  • key (String)
  • value (String)

Returns:

  • (Integer)

    the length of the string after the append operation

See Also:



11
12
13
# File 'lib/oxblood/commands/strings.rb', line 11

def append(key, value)
  run(:APPEND, key, value)
end

#bitcount(key, *interval) ⇒ Integer

Count set bits in a string

Parameters:

  • key (String)
  • interval (Array)

    to count in

Returns:

  • (Integer)

    the number of bits set to 1

See Also:



22
23
24
# File 'lib/oxblood/commands/strings.rb', line 22

def bitcount(key, *interval)
  run(*interval.unshift(:BITCOUNT, key))
end

#bitop(operation, destkey, *keys) ⇒ Integer

Perform bitwise operations between strings

Parameters:

  • operation (String)
  • destkey (String)
  • keys (Array)

Returns:

  • (Integer)

    the size of the string stored in the destination key, that is equal to the size of the longest input string

See Also:



35
36
37
# File 'lib/oxblood/commands/strings.rb', line 35

def bitop(operation, destkey, *keys)
  run(*keys.unshift(:BITOP, operation, destkey))
end

#bitpos(key, bit, *interval) ⇒ Integer

Find first bit set or clear in a string

Parameters:

  • key (String)
  • bit (Integer)
  • interval (Array)

Returns:

  • (Integer)

    the command returns the position of the first bit set to 1 or 0 according to the request

See Also:



48
49
50
# File 'lib/oxblood/commands/strings.rb', line 48

def bitpos(key, bit, *interval)
  run(*interval.unshift(:BITPOS, key, bit))
end

#decr(key) ⇒ Integer, RError

Decrement the integer value of a key by one

Parameters:

  • key (String)

Returns:

  • (Integer)

    the value of key after the decrement

  • (RError)

    if value is not an integer or out of range

See Also:



59
60
61
# File 'lib/oxblood/commands/strings.rb', line 59

def decr(key)
  run(:DECR, key)
end

#decrby(key, decrement) ⇒ Integer, RError

Decrement the integer value of a key by the given number

Parameters:

  • key (String)
  • decrement (Integer)

Returns:

  • (Integer)

    the value of key after the decrement

  • (RError)

    if the key contains a value of the wrong type or contains a string that can not be represented as integer

See Also:



72
73
74
# File 'lib/oxblood/commands/strings.rb', line 72

def decrby(key, decrement)
  run(:DECRBY, key, decrement)
end

#get(key) ⇒ String?

Get the value of a key

Parameters:

  • key (String)

Returns:

  • (String, nil)

    the value of key, or nil when key does not exists

See Also:



82
83
84
# File 'lib/oxblood/commands/strings.rb', line 82

def get(key)
  run(:GET, key)
end

#getbit(key, offset) ⇒ Integer

Returns the bit value at offset in the string value stored at key

Parameters:

  • key (String)
  • offset (Integer)

Returns:

  • (Integer)

    the bit value stored at offset

See Also:



93
94
95
# File 'lib/oxblood/commands/strings.rb', line 93

def getbit(key, offset)
  run(:GETBIT, key, offset)
end

#getrange(key, start_pos, end_pos) ⇒ String

Get a substring of the string stored at a key

Parameters:

  • key (String)
  • start_pos (Integer)
  • end_pos (Integer)

Returns:

  • (String)

    substring

See Also:



105
106
107
# File 'lib/oxblood/commands/strings.rb', line 105

def getrange(key, start_pos, end_pos)
  run(:GETRANGE, key, start_pos, end_pos)
end

#getset(key, value) ⇒ String?

Set the string value of a key and return its old value

Parameters:

  • key (String)
  • value (String)

Returns:

  • (String, nil)

    the old value stored at key, or nil when key did not exist

See Also:



117
118
119
# File 'lib/oxblood/commands/strings.rb', line 117

def getset(key, value)
  run(:GETSET, key, value)
end

#incr(key) ⇒ Integer, RError

Increment the integer value of a key by one

Parameters:

  • key (String)

Returns:

  • (Integer)

    the value of key after the increment

  • (RError)

    if the key contains a value of the wrong type or contains a string that can not be represented as integer

See Also:



129
130
131
# File 'lib/oxblood/commands/strings.rb', line 129

def incr(key)
  run(:INCR, key)
end

#incrby(key, increment) ⇒ Integer

Increment the integer value of a key by the given amount

Parameters:

  • key (String)
  • increment (Integer)

Returns:

  • (Integer)

    the value of key after the increment

See Also:



140
141
142
# File 'lib/oxblood/commands/strings.rb', line 140

def incrby(key, increment)
  run(:INCRBY, key, increment)
end

#incrbyfloat(key, increment) ⇒ String

Increment the float value of a key by the given amount

Parameters:

  • key (String)
  • increment (Float)

Returns:

  • (String)

    the value of key after the increment

See Also:



151
152
153
# File 'lib/oxblood/commands/strings.rb', line 151

def incrbyfloat(key, increment)
  run(:INCRBYFLOAT, key, increment)
end

#mget(*keys) ⇒ Array

Get the values of all the given keys

Parameters:

  • keys (Array<String>)

    to retrieve

Returns:

  • (Array)

    list of values at the specified keys

See Also:



161
162
163
# File 'lib/oxblood/commands/strings.rb', line 161

def mget(*keys)
  run(*keys.unshift(:MGET))
end

#mset(*keys_and_values) ⇒ String

Set multiple keys to multiple values

Parameters:

  • keys_and_values (Array)

Returns:

  • (String)

    ‘OK’

See Also:



171
172
173
# File 'lib/oxblood/commands/strings.rb', line 171

def mset(*keys_and_values)
  run(*keys_and_values.unshift(:MSET))
end

#msetnx(*keys_and_values) ⇒ Integer

Set multiple keys to multiple values, only if none of the keys exist

Parameters:

  • keys_and_values (Array)

Returns:

  • (Integer)

    1 if the all the keys were set, or 0 if no key was set (at least one key already existed)

See Also:



182
183
184
# File 'lib/oxblood/commands/strings.rb', line 182

def msetnx(*keys_and_values)
  run(*keys_and_values.unshift(:MSETNX))
end

#psetex(key, milliseconds, value) ⇒ String

Set the value and expiration in milliseconds of a key

Parameters:

  • key (String)
  • milliseconds (Integer)

    expire time

  • value (String)

Returns:

  • (String)

    ‘OK’

See Also:



194
195
196
# File 'lib/oxblood/commands/strings.rb', line 194

def psetex(key, milliseconds, value)
  run(:PSETEX, key, milliseconds, value)
end

#set(key, value) ⇒ String

TODO:

Add support for set options redis.io/commands/set#options

Set the string value of a key

Parameters:

  • key (String)
  • value (String)

Returns:

  • (String)

    ‘OK’ if SET was executed correctly

See Also:



208
209
210
# File 'lib/oxblood/commands/strings.rb', line 208

def set(key, value)
  run(:SET, key, value)
end

#setbit(key, offset, value) ⇒ Integer

Set or clear the bit at offset in the string value stored at key

Parameters:

  • key (String)
  • offset (Integer)
  • value (String)

Returns:

  • (Integer)

    the original bit value stored at offset

See Also:



220
221
222
# File 'lib/oxblood/commands/strings.rb', line 220

def setbit(key, offset, value)
  run(:SETBIT, key, offset, value)
end

#setex(key, seconds, value) ⇒ String

Set the value and expiration of a key

Parameters:

  • key (String)
  • seconds (Integer)

    expire time

  • value (String)

Returns:

  • (String)

    ‘OK’

See Also:



232
233
234
# File 'lib/oxblood/commands/strings.rb', line 232

def setex(key, seconds, value)
  run(:SETEX, key, seconds, value)
end

#setnx(key, value) ⇒ Integer

Set the value of a key, only if the key does not exist

Parameters:

  • key (String)
  • value (String)

Returns:

  • (Integer)

    1 if the key was set, or 0 if the key was not set

See Also:



243
244
245
# File 'lib/oxblood/commands/strings.rb', line 243

def setnx(key, value)
  run(:SETNX, key, value)
end

#setrange(key, offset, value) ⇒ Integer

Overwrite part of a string at key starting at the specified offset

Parameters:

  • key (String)
  • offset (Integer)
  • value (String)

Returns:

  • (Integer)

    the length of the string after it was modified by the command

See Also:



256
257
258
# File 'lib/oxblood/commands/strings.rb', line 256

def setrange(key, offset, value)
  run(:SETRANGE, key, offset, value)
end

#strlen(key) ⇒ Integer

Get the length of the value stored in a key

Parameters:

  • key (String)

Returns:

  • (Integer)

    the length of the string at key, or 0 when key does not exist

See Also:



267
268
269
# File 'lib/oxblood/commands/strings.rb', line 267

def strlen(key)
  run(:STRLEN, key)
end