module Oxblood::Commands::Strings
Public Instance Methods
Append a value to a key @see redis.io/commands/append
@param [String] key @param [String] value
@return [Integer] the length of the string after the append operation
# File lib/oxblood/commands/strings.rb, line 11 def append(key, value) run(:APPEND, key, value) end
Count set bits in a string @see redis.io/commands/bitcount
@param [String] key @param [Array] interval to count in
@return [Integer] the number of bits set to 1
# File lib/oxblood/commands/strings.rb, line 22 def bitcount(key, *interval) run(*interval.unshift(:BITCOUNT, key)) end
Perform bitwise operations between strings @see redis.io/commands/bitop
@param [String] operation @param [String] destkey @param [Array] keys
@return [Integer] the size of the string stored in the destination key,
that is equal to the size of the longest input string
# File lib/oxblood/commands/strings.rb, line 35 def bitop(operation, destkey, *keys) run(*keys.unshift(:BITOP, operation, destkey)) end
Find first bit set or clear in a string @see redis.io/commands/bitpos
@param [String] key @param [Integer] bit @param [Array] interval
@return [Integer] the command returns the position of the first bit set to
1 or 0 according to the request
# File lib/oxblood/commands/strings.rb, line 48 def bitpos(key, bit, *interval) run(*interval.unshift(:BITPOS, key, bit)) end
Decrement the integer value of a key by one @see redis.io/commands/decr
@param [String] key
@return [Integer] the value of key after the decrement @return [RError] if value is not an integer or out of range
# File lib/oxblood/commands/strings.rb, line 59 def decr(key) run(:DECR, key) end
Decrement the integer value of a key by the given number @see redis.io/commands/decrby
@param [String] key @param [Integer] decrement
@return [Integer] the value of key after the decrement @return [RError] if the key contains a value of the wrong type or contains
a string that can not be represented as integer
# File lib/oxblood/commands/strings.rb, line 72 def decrby(key, decrement) run(:DECRBY, key, decrement) end
Get the value of a key @see redis.io/commands/get
@param [String] key
@return [String, nil] the value of key, or nil when key does not exists
# File lib/oxblood/commands/strings.rb, line 82 def get(key) run(:GET, key) end
Returns the bit value at offset in the string value stored at key @see redis.io/commands/getbit
@param [String] key @param [Integer] offset
@return [Integer] the bit value stored at offset
# File lib/oxblood/commands/strings.rb, line 93 def getbit(key, offset) run(:GETBIT, key, offset) end
Get a substring of the string stored at a key @see redis.io/commands/getrange
@param [String] key @param [Integer] start_pos @param [Integer] end_pos
@return [String] substring
# File lib/oxblood/commands/strings.rb, line 105 def getrange(key, start_pos, end_pos) run(:GETRANGE, key, start_pos, end_pos) end
Set the string value of a key and return its old value @see redis.io/commands/getset
@param [String] key @param [String] value
@return [String, nil] the old value stored at key, or nil when
key did not exist
# File lib/oxblood/commands/strings.rb, line 117 def getset(key, value) run(:GETSET, key, value) end
Increment the integer value of a key by one @see redis.io/commands/incr
@param [String] key
@return [Integer] the value of key after the increment @return [RError] if the key contains a value of the wrong type or contains
a string that can not be represented as integer
# File lib/oxblood/commands/strings.rb, line 129 def incr(key) run(:INCR, key) end
Increment the integer value of a key by the given amount @see redis.io/commands/incrby
@param [String] key @param [Integer] increment
@return [Integer] the value of key after the increment
# File lib/oxblood/commands/strings.rb, line 140 def incrby(key, increment) run(:INCRBY, key, increment) end
Increment the float value of a key by the given amount @see redis.io/commands/incrbyfloat
@param [String] key @param [Float] increment
@return [String] the value of key after the increment
# File lib/oxblood/commands/strings.rb, line 151 def incrbyfloat(key, increment) run(:INCRBYFLOAT, key, increment) end
Get the values of all the given keys @see redis.io/commands/mget
@param [Array<String>] keys to retrieve
@return [Array] list of values at the specified keys
# File lib/oxblood/commands/strings.rb, line 161 def mget(*keys) run(*keys.unshift(:MGET)) end
Set multiple keys to multiple values @see redis.io/commands/mset
@param [Array] keys_and_values
@return [String] 'OK'
# File lib/oxblood/commands/strings.rb, line 171 def mset(*keys_and_values) run(*keys_and_values.unshift(:MSET)) end
Set multiple keys to multiple values, only if none of the keys exist @see redis.io/commands/msetnx
@param [Array] keys_and_values
@return [Integer] 1 if the all the keys were set, or
0 if no key was set (at least one key already existed)
# File lib/oxblood/commands/strings.rb, line 182 def msetnx(*keys_and_values) run(*keys_and_values.unshift(:MSETNX)) end
Set the value and expiration in milliseconds of a key @see redis.io/commands/psetex
@param [String] key @param [Integer] milliseconds expire time @param [String] value
@return [String] 'OK'
# File lib/oxblood/commands/strings.rb, line 194 def psetex(key, milliseconds, value) run(:PSETEX, key, milliseconds, value) end
Set the string value of a key @see redis.io/commands/set
@todo Add support for set options
http://redis.io/commands/set#options
@param [String] key @param [String] value
@return [String] 'OK' if SET was executed correctly
# File lib/oxblood/commands/strings.rb, line 208 def set(key, value) run(:SET, key, value) end
Set or clear the bit at offset in the string value stored at key @see redis.io/commands/setbit
@param [String] key @param [Integer] offset @param [String] value
@return [Integer] the original bit value stored at offset
# File lib/oxblood/commands/strings.rb, line 220 def setbit(key, offset, value) run(:SETBIT, key, offset, value) end
Set the value and expiration of a key @see redis.io/commands/setex
@param [String] key @param [Integer] seconds expire time @param [String] value
@return [String] 'OK'
# File lib/oxblood/commands/strings.rb, line 232 def setex(key, seconds, value) run(:SETEX, key, seconds, value) end
Set the value of a key, only if the key does not exist @see redis.io/commands/setnx
@param [String] key @param [String] value
@return [Integer] 1 if the key was set, or 0 if the key was not set
# File lib/oxblood/commands/strings.rb, line 243 def setnx(key, value) run(:SETNX, key, value) end
Overwrite part of a string at key starting at the specified offset @see redis.io/commands/setrange
@param [String] key @param [Integer] offset @param [String] value
@return [Integer] the length of the string after it was modified by
the command
# File lib/oxblood/commands/strings.rb, line 256 def setrange(key, offset, value) run(:SETRANGE, key, offset, value) end
Get the length of the value stored in a key @see redis.io/commands/strlen
@param [String] key
@return [Integer] the length of the string at key,
or 0 when key does not exist
# File lib/oxblood/commands/strings.rb, line 267 def strlen(key) run(:STRLEN, key) end