module Protocol::Redis::Methods::Strings

Public Instance Methods

append(key, value) click to toggle source

Append a value to a key. O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation. @see redis.io/commands/append @param key [Key] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 32
def append(key, value)
        call('APPEND', key, value)
end
bitcount(key, *range) click to toggle source

Count set bits in a string. O(N). @see redis.io/commands/bitcount @param key [Key]

# File lib/protocol/redis/methods/strings.rb, line 39
def bitcount(key, *range)
        call('BITCOUNT', key, *range)
end
decr(key) click to toggle source

Decrement the integer value of a key by one. O(1). @see redis.io/commands/decr @param key [Key]

# File lib/protocol/redis/methods/strings.rb, line 46
def decr(key)
        call('DECR', key)
end
decrby(key, decrement) click to toggle source

Decrement the integer value of a key by the given number. O(1). @see redis.io/commands/decrby @param key [Key] @param decrement [Integer]

# File lib/protocol/redis/methods/strings.rb, line 54
def decrby(key, decrement)
        call('DECRBY', key, decrement)
end
get(key) click to toggle source

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

# File lib/protocol/redis/methods/strings.rb, line 61
def get(key)
        call('GET', key)
end
getbit(key, offset) click to toggle source

Returns the bit value at offset in the string value stored at key. O(1). @see redis.io/commands/getbit @param key [Key] @param offset [Integer]

# File lib/protocol/redis/methods/strings.rb, line 69
def getbit(key, offset)
        call('GETBIT', key, offset)
end
getrange(key, start_index, end_index) click to toggle source

Get a substring of the string stored at a key. O(N) where N is the length of the returned string. The complexity is ultimately determined by the returned length, but because creating a substring from an existing string is very cheap, it can be considered O(1) for small strings. @see redis.io/commands/getrange @param key [Key] @param start [Integer] @param end [Integer]

# File lib/protocol/redis/methods/strings.rb, line 78
def getrange(key, start_index, end_index)
        call('GETRANGE', key, start_index, end_index)
end
getset(key, value) click to toggle source

Set the string value of a key and return its old value. O(1). @see redis.io/commands/getset @param key [Key] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 86
def getset(key, value)
        call('GETSET', key, value)
end
incr(key) click to toggle source

Increment the integer value of a key by one. O(1). @see redis.io/commands/incr @param key [Key]

# File lib/protocol/redis/methods/strings.rb, line 93
def incr(key)
        call('INCR', key)
end
incrby(key, increment) click to toggle source

Increment the integer value of a key by the given amount. O(1). @see redis.io/commands/incrby @param key [Key] @param increment [Integer]

# File lib/protocol/redis/methods/strings.rb, line 101
def incrby(key, increment)
        call('INCRBY', key, increment)
end
incrbyfloat(key, increment) click to toggle source

Increment the float value of a key by the given amount. O(1). @see redis.io/commands/incrbyfloat @param key [Key] @param increment [Double]

# File lib/protocol/redis/methods/strings.rb, line 109
def incrbyfloat(key, increment)
        call('INCRBYFLOAT', key, increment)
end
mget(key, *keys) click to toggle source

Get the values of all the given keys. O(N) where N is the number of keys to retrieve. @see redis.io/commands/mget @param key [Key]

# File lib/protocol/redis/methods/strings.rb, line 116
def mget(key, *keys)
        call('MGET', key, *keys)
end
mset(pairs) click to toggle source

Set multiple keys to multiple values. O(N) where N is the number of keys to set. @see redis.io/commands/mset

# File lib/protocol/redis/methods/strings.rb, line 122
def mset(pairs)
        flattened_pairs = pairs.keys.zip(pairs.values).flatten
        
        call('MSET', *flattened_pairs)
end
msetnx(pairs) click to toggle source

Set multiple keys to multiple values, only if none of the keys exist. O(N) where N is the number of keys to set. @see redis.io/commands/msetnx

# File lib/protocol/redis/methods/strings.rb, line 130
def msetnx(pairs)
        flattened_pairs = pairs.keys.zip(pairs.values).flatten
        
        call('MSETNX', *flattened_pairs)
end
psetex(key, milliseconds, value) click to toggle source

Set the value and expiration in milliseconds of a key. O(1). @see redis.io/commands/psetex @param key [Key] @param milliseconds [Integer] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 141
def psetex(key, milliseconds, value)
        call('PSETEX', key, milliseconds, value)
end
set(key, value, update: nil, seconds: nil, milliseconds: nil) click to toggle source

Set the string value of a key. O(1). @see redis.io/commands/set @param key [Key] @param value [String] @param expiration [Enum] @param update [Boolean, nil] If true, only update elements that already exist (never add elements). If false, don't update existing elements (only add new elements).

# File lib/protocol/redis/methods/strings.rb, line 151
def set(key, value, update: nil, seconds: nil, milliseconds: nil)
        arguments = []

        if seconds
                arguments << 'EX' << seconds
        end

        if milliseconds
                arguments << 'PX' << milliseconds
        end

        if update == true
                arguments << "XX"
        elsif update == false
                arguments << "NX"
        end

        call('SET', key, value, *arguments)
end
setbit(key, offset, value) click to toggle source

Sets or clears the bit at offset in the string value stored at key. O(1). @see redis.io/commands/setbit @param key [Key] @param offset [Integer] @param value [Integer]

# File lib/protocol/redis/methods/strings.rb, line 176
def setbit(key, offset, value)
        call('SETBIT', key, offset, value)
end
setex(key, seconds, value) click to toggle source

Set the value and expiration of a key. O(1). @see redis.io/commands/setex @param key [Key] @param seconds [Integer] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 185
def setex(key, seconds, value)
        call('SETEX', key, seconds, value)
end
setnx(key, value) click to toggle source

Set the value of a key, only if the key does not exist. O(1). @return [Boolean] if the key was set. @see redis.io/commands/setnx @param key [Key] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 194
def setnx(key, value)
        call('SETNX', key, value) == 1
end
setrange(key, offset, value) click to toggle source

Overwrite part of a string at key starting at the specified offset. O(1), not counting the time taken to copy the new string in place. Usually, this string is very small so the amortized complexity is O(1). Otherwise, complexity is O(M) with M being the length of the value argument. @see redis.io/commands/setrange @param key [Key] @param offset [Integer] @param value [String]

# File lib/protocol/redis/methods/strings.rb, line 203
def setrange(key, offset, value)
        call('SETRANGE', key, offset, value)
end
strlen(key) click to toggle source

Get the length of the value stored in a key. O(1). @see redis.io/commands/strlen @param key [Key]

# File lib/protocol/redis/methods/strings.rb, line 210
def strlen(key)
        call('STRLEN', key)
end