module Redis::Commands

Overview

Definition of all Redis commands except pipelining and transactions.

Direct including types

Defined in:

redis/commands.cr

Instance Method Summary

Instance Method Detail

def append(key, value) #

If key already exists and is a string, this command appends the value at the end of the string. If key does not exist it is created and set as an empty string, so APPEND will be similar to SET in this special case.

Return value: Integer, the length of the string after the append operation.

Example:

redis.append("foo", " world")

[View source]
def auth(password) #

Request for authentication in a password-protected Redis server.

Return value: "OK"


[View source]
def bitcount(key, from = nil, to = nil) #

Count the number of set bits (population counting) in a string. By default all the bytes contained in the string are examined.

Options:

  • from / to - It is possible to specify the counting operation only in an interval passing the additional arguments from and to.

Return value Integer, the number of bits set to 1.

Example:

redis.bitcount("foo", 0, 0)

[View source]
def bitop(operation, key, *keys) #

Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.

Return value: Integer, the size of the string stored in the destination key, that is equal to the size of the longest input string.

Example:

redis.bitop("and", "dest", "key1", "key2")

[View source]
def bitpos(key, bit, start = nil, to = nil) #

Return the position of the first bit set to 1 or 0 in a string.

Options:

  • start / to - By default, all the bytes contained in the string are examined. It is possible to look for bits only in a specified interval passing the additional arguments start and to (it is possible to just pass start, the operation will assume that the to is the last byte of the string.

Return value: Integer, the command returns the position of the first bit set to 1 or 0 according to the request.

Example:

redis.set("mykey", "0")
redis.bitpos("mykey", 1) # => 2

[View source]
def blpop(keys, timeout_in_seconds) #

BLPOP is a blocking list pop primitive. It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given.

The timeout_in_seconds argument is interpreted as an integer value specifying the maximum number of seconds to block

Return value: Array, specifically:

  • An array of nils when no element could be popped and the timeout expired.
  • An array of two-element arrays with the first element being the name of the key where an element was popped and the second element being the value of the popped element.

Example:

redis.blpop(["myotherlist", "mylist"], 1) # => ["mylist", "hello"]

[View source]
def brpop(keys, timeout_in_seconds) #

BRPOP is a blocking list pop primitive. It is the blocking version of RPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given.

The timeout_in_seconds argument is interpreted as an integer value specifying the maximum number of seconds to block.

Return value: Array, specifically:

  • An array of nils when no element could be popped and the timeout expired.
  • An array of two-element arrays with the first element being the name of the key where an element was popped and the second element being the value of the popped element.

Example:

redis.brpop(["myotherlist", "mylist"], 1) # => ["mylist", "world"]

[View source]
def brpoplpush(source, destination, timeout_in_seconds = nil) #

BRPOPLPUSH is the blocking variant of RPOPLPUSH. When source contains elements, this command behaves exactly like RPOPLPUSH.

Options:

  • timeout_in_seconds - interpreted as an integer value specifying the maximum number of seconds to block

See RPOPLPUSH for more information.

Return value: String, the element being popped from source and pushed to destination. If timeout is reached, nil is returned.

Example:

redis.brpoplpush("source", "destination", 0)

[View source]
def decr(key) #

Decrements the number stored at key by one.

Return value: Integer, the value of key after the decrement


[View source]
def decrby(key, decrement) #

Decrements the number stored at key by decrement.

Return value: Integer, the value of key after the decrement


[View source]
def del(*keys) #

Removes the specified keys.

Return value: Integer, the number of keys that were removed.

Example:

redis.del("some", "keys", "to", "delete")

[View source]
def dump(key) #

Serialize the value stored at key in a Redis-specific format and return it to the user.

Return value: String, the serialized value.


[View source]
def echo(message) #

Returns the given message.

Example:

redis.echo("Hello Redis") # => "Hello Redis"

[View source]
def eval(script : String, keys = [] of RedisValue, args = [] of RedisValue) #

EVAL and EVALSHA are used to evaluate scripts using the Lua interpreter built into Redis starting from version 2.6.0.

Return value: Array(String), depends on the executed script

Example:

redis.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", ["key1", "key2"], ["first art", "second arg"])

[View source]
def evalsha(sha1, keys = [] of RedisValue, args = [] of RedisValue) #

EVAL and EVALSHA are used to evaluate scripts using the Lua interpreter built into Redis starting from version 2.6.0.

Return value: Array(String), depends on the executed script


[View source]
def exists(key) #

Returns if key exists.

Return value:

  • 1 if the key exists.
  • 0 if the key does not exist.

[View source]
def expire(key, seconds) #

Set a timeout on key.

Return value: Integeger, specifically:

  • 1 if the timeout was set.
  • 0 if key does not exist or the timeout could not be set.

Example:

redis.expire("temp", 2)

[View source]
def expireat(key, unix_date) #

EXPIREAT has the same effect and semantic as EXPIRE, but instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp (seconds since January 1, 1970).

Return value: Integeger, specifically:

  • 1 if the timeout was set.
  • 0 if key does not exist or the timeout could not be set.

[View source]
def flushall #

Flush all databases.

Return value: "OK"


[View source]
def flushdb #

Flush the current database.

Return value: "OK"


[View source]
def get(key) #

Get the value of key.

Return value: a String or nil

Example:

redis.set("foo", "test")
redis.get("foo") # => "test"

[View source]
def getbit(key, index) #

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

Return value: Integer, the bit value stored at offset.


[View source]
def getrange(key, start_index, end_index) #

Returns the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).

Example:

redis.set("foo", "This is a string")
redis.getrange("foo", 0, 3)   # => "This"
redis.getrange("foo", -3, -1) # => "ing"

[View source]
def getset(key, value) #

Atomically sets key to value and returns the old value stored at key.

Return value: String, the old value stored at key, or nil when key did not exist.

Example:

redis.getset("foo", "new") # => (the old value)

[View source]
def hdel(key, field) #

Removes the specified fields from the hash stored at key.

Return value: Integer, the number of fields that were removed from the hash, not including specified but non existing fields.


[View source]
def hexists(key, field) #

Returns if field is an existing field in the hash stored at key.

Return value: Integer, specifically:

  • 1 if the hash contains field.
  • 0 if the hash does not contain field, or key does not exist.

[View source]
def hget(key, field) #

Returns the value associated with field in the hash stored at key.

Return value: String, the value associated with field, or nil

Example:

redis.hget("myhash", "a") # => "434"

[View source]
def hgetall(key) #

Returns all fields and values of the hash stored at key.

Return value: Array(String) of fields and their values stored in the hash, or an empty array when key does not exist.


[View source]
def hincrby(key, field, increment) #

Increments the number stored at field in the hash stored at key by increment.

Return value: Integer, the value at field after the increment operation.

Example:

redis.hincrby("myhash", "field1", "3") # => 4

[View source]
def hincrbyfloat(key, field, increment) #

Increment the specified field of an hash stored at key, and representing a floating point number, by the specified increment.

Return value: String, the value at field after the increment operation.


[View source]
def hkeys(key) #

Returns all field names in the hash stored at key.

Return value: Array(String) - list of fields in the hash, or an empty list when key does not exist.


[View source]
def hlen(key) #

Returns the number of fields contained in the hash stored at key.

Return value: Integer, the number of fields in the hash, or 0 when key does not exist.


[View source]
def hmget(key, *fields) #

Returns the values associated with the specified fields in the hash stored at key.

Return value: Array(String), the list of values associated with the given fields, in the same order as they are requested.


[View source]
def hmset(key, hash) #

Sets the specified fields to their respective values in the hash stored at key.

Return value: "OK"


[View source]
def hscan(key, cursor, match = nil, count = nil) #

The SCAN command and the closely related commands SSCAN, HSCAN and ZSCAN are used in order to incrementally iterate over a collection of elements.

Options:

  • match - It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the KEYS command that takes a pattern as only argument.
  • count - While SCAN does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of SCAN using the COUNT option.

Return value: Array(String), two elements, a field and a value, for every returned element of the Hash.


[View source]
def hset(key, field, value) #

Sets field in the hash stored at key to value.

Return value: Integer, specifically:

  • 1 if field is a new field in the hash and value was set.
  • 0 if field already exists in the hash and the value was updated.

Example:

redis.hset("myhash", "a", "434")

[View source]
def hsetnx(key, field, value) #

Sets field in the hash stored at key to value, only if field does not yet exist.

Return value: Integer, specifically:

  • 1 if field is a new field in the hash and value was set.
  • 0 if field already exists in the hash and no operation was performed.

[View source]
def hvals(key) #

Returns all values in the hash stored at key.

Return value: Array(String), the list of values in the hash, or an empty list when key does not exist.


[View source]
def incr(key) #

Increments the number stored at key by one.

Return value: Integer: the value of key after the increment

Example:

redis.set("foo", "3")
redis.incr("foo") # => 4

[View source]
def incrby(key, increment) #

Increments the number stored at key by increment.

Return value: Integer, the value of key after the increment

Example:

redis.incrby("foo", 4)

[View source]
def incrbyfloat(key, increment) #

Increment the string representing a floating point number stored at key by the specified increment.

Return value: Integer, the value of key after the increment

Example:

redis.incrbyfloat("foo", 2.5)

[View source]
def keys(pattern) #

Returns all keys matching pattern.

Return value: Array(String), array of keys matching pattern.

Example:

redis.keys("callmemaybe")

[View source]
def lindex(key, index) #

Returns the element at index index in the list stored at key.

Return value: String, the requested element, or nil when index is out of range.


[View source]
def linsert(key, where, pivot, value) #

Inserts value in the list stored at key either before or after the reference value pivot.

Options:

  • where - either "BEFORE" or "AFTER"

Return value: Integer, the length of the list after the insert operation, or -1 when the value pivot was not found.


[View source]
def llen(key) #

Returns the length of the list stored at key.

Return value: Integer, the length of the list at key.


[View source]
def lpop(key) #

Removes and returns the first element of the list stored at key.

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

Example:

redis.lpop("mylist")

[View source]
def lpush(key, values : Array(RedisValue)) #

[View source]
def lpush(key, *values) #

Insert all the specified values at the head of the list stored at key.

Return value: Integer, the length of the list after the push operation.


[View source]
def lpushx(key, value) #

Inserts value at the head of the list stored at key, only if key already exists and holds a list.

Return value: Integer, the length of the list after the push operation.


[View source]
def lrange(key, from, to) #

Returns the specified elements of the list stored at key.

Return value: Array(String), the list of elements in the specified range.

Example:

redis.lrange("mylist", 0, 2)

[View source]
def lrem(key, count, value) #

Removes the first count occurrences of elements equal to value from the list stored at key.

Return value: Integer, the number of removed elements.

Example:

redis.lrem("mylist", 1, "my")

[View source]
def lset(key, index, value) #

Sets the list element at index to value.

Return value: "OK"


[View source]
def ltrim(key, start, stop) #

Trim an existing list so that it will contain only the specified range of elements specified.

Return value: "OK"


[View source]
def mget(*keys) #

Returns the values of all specified keys.

Return value: Array(String), the list of values at the specified keys. For every key that does not hold a string value or does not exist, nil is returned.

Example:

redis.set("foo1", "test1")
redis.set("foo2", "test2")
redis.mget("foo1", "foo2") # => ["test1", "test2"]

[View source]
def mset(hash) #

Sets the given keys to their respective values as defined in the hash.

Return value: "OK"

Example:

redis.mset({"foo1": "bar1", "foo2": "bar2"})

[View source]
def msetnx(hash) #

Sets the given keys to their respective values as defined in the hash. MSETNX will not perform any operation at all even if just a single key already exists.

Return value: Integer, specifically:

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

Example:

redis.msetnx({"key1": "hello", "key2": "there"})

[View source]
def persist(key) #

Remove the existing timeout on key, turning the key from volatile (a key with an expire set) to persistent (a key that will never expire as no timeout is associated).

Return value: Integer, specifically:

  • 1 if the timeout was removed.
  • 0 if key does not exist or does not have an associated timeout.

[View source]
def pexpire(key, milis) #

This command works exactly like EXPIRE but the time to live of the key is specified in milliseconds instead of seconds.

Return value: Integeger, specifically:

  • 1 if the timeout was set.
  • 0 if key does not exist or the timeout could not be set.

[View source]
def pexpireat(key, unix_date_in_millis) #

PEXPIREAT has the same effect and semantic as EXPIREAT, but the Unix time at which the key will expire is specified in milliseconds instead of seconds.

Return value: Integeger, specifically:

  • 1 if the timeout was set.
  • 0 if key does not exist or the timeout could not be set.

[View source]
def pfadd(key, *values) #

Adds all the element arguments to the HyperLogLog data structure stored at the variable name specified as first argument.

Return value: Integer: 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise.

Example:

redis.pfadd("hll", "a", "b", "c", "d", "e", "f", "g") # => 1

[View source]
def pfcount(*keys) #

When called with a single key, returns the approximated cardinality computed by the HyperLogLog data structure stored at the specified variable, which is 0 if the variable does not exist.

Return value: Integer, the approximated number of unique elements observed via PFADD.


[View source]
def pfmerge(*keys) #

Merge multiple HyperLogLog values into an unique value that will approximate the cardinality of the union of the observed Sets of the source HyperLogLog structures.

Return value: "OK".


[View source]
def ping #

Returns PONG. This command is often used to test if a connection is still alive, or to measure latency.

Example:

redis.ping # => "PONG"

[View source]
def psetex(key, expire_in_milis, value) #

PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

Return value: "OK"


[View source]
def psubscribe(*channel_patterns, &callback_setup_block : Subscription -> ) #

Subscribes to channel patterns and enters a subscription loop, waiting for events.

The method yields to the given block and passes a Subscription object, on which you can set your callbacks for the event subscription.

The subscription loop will end once you unsubscribe.


[View source]
def psubscribe(*channel_patterns) #

Subscribes to more channel patterns while already being in a subscription loop.


[View source]
def pttl(key) #

Like TTL this command returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds.

Return value: Integer, the TTL in milliseconds, or a negative value in order to signal an error.


[View source]
def publish(channel, message) #

Posts a message to the given channel.

Return value: Integer, the number of clients that received the message.

Example:

redis.publish("mychannel", "some message")

[View source]
def punsubscribe(*channel_patterns) #

Unsubscribes the client from the given patterns, or from all of them if none is given.


[View source]
def quit #

Ask the server to close the connection. The connection is closed as soon as all pending replies have been written to the client.

Return value: "OK"


[View source]
def randomkey #

Return a random key from the currently selected database.


[View source]
def rename(old_key, new_key) #

Renames old_key to newkey.

Return value: "OK"

Example:

redis.rename("old_name", "new_name")

[View source]
def renamenx(old_key, new_key) #

Renames old_key to newkey if newkey does not yet exist.

Return value: "OK"

Example:

redis.renamenx("old_name", "new_name")

[View source]
def restore(key, ttl_in_milis : Int, serialized_value : String, replace = false) #

Create a key associated with a value that is obtained by deserializing the provided serialized value (obtained via DUMP).

Return value: The command returns "OK" on success.


[View source]
def rpop(key) #

Removes and returns the last element of the list stored at key.

Return value: "OK"


[View source]
def rpoplpush(source, destination) #

Atomically returns and removes the last element (tail) of the list stored at source, and pushes the element at the first element (head) of the list stored at destination.

Return value: String, the element being popped and pushed.


[View source]
def rpush(key, *values) #

Insert all the specified values at the tail of the list stored at key.

Return value: Integer, the length of the list after the push operation.

Example:

redis.rpush("mylist", "1", "2", "3")

[View source]
def rpushx(key, value) #

Inserts value at the tail of the list stored at key, only if key already exists and holds a list.

Return value: Integer, the length of the list after the push operation.


[View source]
def sadd(key, *values) #

Add the specified members to the set stored at key.

Return value: Integer, the number of elements that were added to the set, not including all the elements already present into the set.


[View source]
def scan(cursor, match = nil, count = nil) #

The SCAN command and the closely related commands SSCAN, HSCAN and ZSCAN are used in order to incrementally iterate over a collection of elements.

Options:

  • match - It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the KEYS command that takes a pattern as only argument.
  • count - While SCAN does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of SCAN using the COUNT option.

Return value: Array of String, a list of keys.

Example:

redis.scan(0)

[View source]
def scard(key) #

Returns the set cardinality (number of elements) of the set stored at key.


[View source]
def script_exists(sha1_array : Array(Reference)) #

Returns information about the existence of the scripts in the script cache.

Return value: The command returns an array of integers that correspond to the specified SHA1 digest arguments. For every corresponding SHA1 digest of a script that actually exists in the script cache, an 1 is returned, otherwise 0 is returned.


[View source]
def script_flush #

Flush the Lua scripts cache.

Return value: "OK"


[View source]
def script_kill #

Kills the currently executing Lua script, assuming no write operation was yet performed by the script.

Return value: "OK"


[View source]
def script_load(script : String) #

Load a script into the scripts cache, without executing it.

Return value: String, the SHA1 digest of the script added into the script cache.

Example:

redis.script_load("return {KEYS[1],ARGV[1]}") # => "a191862bfe0bd3bec995befcd060582bf4bdbd77"

[View source]
def sdiff(*keys) #

Returns the members of the set resulting from the difference between the first set and all the successive sets.

Return value: Array(String), a list with members of the resulting set.


[View source]
def sdiffstore(destination, *keys) #

This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination.

Return value: Integer, the number of elements in the resulting set.


[View source]
def select(database_number) #

Select the DB with having the specified zero-based numeric index.

Return value: "OK"


[View source]
def set(key, value, ex = nil, px = nil, nx = nil, xx = nil) #

Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Any previous time to live associated with the key is discarded on successful SET operation.

Options:

  • Starting with Redis 2.6.12 SET supports a set of options that modify its behavior:
  • ex -- Set the specified expire time, in seconds.
  • px -- Set the specified expire time, in milliseconds.
  • nx -- Only set the key if it does not already exist.
  • xx -- Only set the key if it already exist.

Return value:

  • OK if SET was executed correctly.
  • Null reply: nil is returned if the SET operation was not performed because the user specified the NX or XX option but the condition was not met.

Example:

redis.set("foo", "test")
redis.set("bar", "test", ex: 7)

[View source]
def setbit(key, index, value) #

Sets or clears the bit at offset in the string value stored at key.

Return value: Integer: the original bit value stored at offset.

Example:

redis.setbit("mykey", 7, 1)

[View source]
def setex(key, expire_in_seconds, value) #

Set key to hold the string value and set key to timeout after a given number of seconds.

Return value: "OK"

Example:

redis.setex("foo", 3, "bar")

[View source]
def setnx(key, value) #

Set key to hold string value if key does not exist.

Return value: Integer, specifically:

  • 1 if the key was set
  • 0 if the key was not set

[View source]
def setrange(key, start_index, value) #

Overwrites part of the string stored at key, starting at the specified offset, for the entire length of value.

Return value: Integer, the length of the string after it was modified by the command.

Example:

redis.setrange("foo", 6, "Redis")

[View source]
def sinter(*keys) #

Returns the members of the set resulting from the intersection of all the given sets.

Return value: Array(String), an array with members of the resulting set.


[View source]
def sinterstore(destination_key, *keys) #

This command is equal to SINTER, but instead of returning the resulting set, it is stored in destination.

Return value: Integer, the number of elements in the resulting set.

Example:

redis.sinterstore("destination", "key1", "key2")

[View source]
def sismember(key, value) #

Returns if member is a member of the set stored at key.

Return value: Integer, specifically:

  • 1 if the element is a member of the set.
  • 0 if the element is not a member of the set, or if key does not exist.

[View source]
def smembers(key) #

Returns all the members of the set value stored at key.

Return value: Array(String), all elements of the set.


[View source]
def smove(source, destination, member) #

Move member from the set at source to the set at destination.

Return value: Integer, specifically:

  • 1 if the element is moved.
  • 0 if the element is not a member of source and no operation was performed.

[View source]
def sort(key, by = nil, limit = nil, get : Array(RedisValue) | Nil = nil, order = "ASC", alpha = false, store = nil) #

Returns or stores the elements contained in the list, set or sorted set at key.

Options:

  • by - pattern for sorting by external keys
  • limit - Array of 2 strings [offset, count]
  • get - pattern for retrieving external keys
  • order - either 'ASC' or 'DESC'
  • alpha - true to sort lexicographically
  • store - key of destination list to store the result in

Return value: Array(String), the list of sorted elements.

Example:

redis.sort("mylist")                # => [...]
redis.sort("mylist", order: "DESC") # => [...]

[View source]
def spop(key, count = nil) #

Removes and returns one or more random elements from the set value store at key.

The count argument will be available in a later Redis version and is not available in 2.6, 2.8, 3.0

Return value: The removed element, or nil when key does not exist.


[View source]
def srandmember(key, count = nil) #

When called with just the key argument, return a random element from the set value stored at key.

Options:

  • count - Starting from Redis version 2.6, when called with the additional count argument, return an array of count distinct elements if count is positive. If called with a negative count the behavior changes and the command is allowed to return the same element multiple times.

Return value:

  • String: without the additional count argument the command returns a Bulk Reply with the randomly selected element, or nil when key does not exist.
  • Array: when the additional count argument is passed the command returns an array of elements, or an empty array when key does not exist.

[View source]
def srem(key, *values) #

Remove the specified members from the set stored at key.

Return value: Integer, The number of members that were removed from the set, not including non existing members.

Example:

redis.srem("myset", "Hello")

[View source]
def sscan(key, cursor, match = nil, count = nil) #

The SCAN command and the closely related commands SSCAN, HSCAN and ZSCAN are used in order to incrementally iterate over a collection of elements.

Options:

  • match - It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the KEYS command that takes a pattern as only argument.
  • count - While SCAN does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of SCAN using the COUNT option.

Return value: Array(String), a list of Set members.

Example:

redis.sscan("myset", 0)

[View source]
def strlen(key) #

Returns the length of the string value stored at key.

Return value: Integer, the length of the string at key, or 0 when key does not exist.


[View source]
def subscribe(*channels, &callback_setup_block : Subscription -> ) #

Subscribes to channels and enters a subscription loop, waiting for events.

The method yields to the given block and passes a Subscription object, on which you can set your callbacks for the event subscription.

The subscription loop will end once you unsubscribe.

See also: Subscription class See also: Example subscribe.cr

Example:

redis.subscribe("mychannel") do |on|
  on.message do |channel, message|
    puts "Received message: #{message}"
    if message == "goodbye pal"
      redis.unsubscribe
    end
  end
end

[View source]
def subscribe(*channels) #

Subscribes to more channels while already being in a subscription loop.


[View source]
def sunion(*keys) #

Returns the members of the set resulting from the union of all the given sets.

Return value: Array(String), with members of the resulting set.


[View source]
def sunionstore(destination, *keys) #

This command is equal to SUNION, but instead of returning the resulting set, it is stored in destination.

Return value: Integer, the number of elements in the resulting set.


[View source]
def ttl(key) #

Returns the remaining time to live of a key that has a timeout.

Return value: Integer: TTL in seconds, or a negative value in order to signal an error (see the description above).


[View source]
def type(key) #

Returns the string representation of the type of the value stored at key.

Return value: String, the type of key, or none when key does not exist.

Example:

redis.set("foo", 3)
redis.type("foo") # => "string"

[View source]
def unsubscribe(*channels) #

Unsubscribes the client from the given channels, or from all of them if none is given.


[View source]
def unwatch #

Flushes all the previously watched keys for a transaction.

Return value: "OK"


[View source]
def watch(*keys) #

Marks the given keys to be watched for conditional execution of a transaction.

Return value: "OK"


[View source]
def zadd(key, scores_and_members : Array(RedisValue)) #

[View source]
def zadd(key, *scores_and_members) #

Adds all the specified members with the specified scores to the sorted set stored at key.

Return value: Integer, the number of elements added to the sorted sets, not including elements already existing for which the score was updated.

Example:

redis.zadd("myzset", 1, "one")
redis.zadd("myzset", 2, "two", 3, "three")

[View source]
def zcard(key) #

Returns the sorted set cardinality (number of elements) of the sorted set stored at key.

Return value: Integer, the cardinality (number of elements) of the sorted set, or 0 if key does not exist.


[View source]
def zcount(key, min, max) #

Returns the number of elements in the sorted set at key with a score between min and max.

Return value: Integer, the number of elements in the specified score range.


[View source]
def zincrby(key, increment, member) #

Increments the score of member in the sorted set stored at key by increment.

Return value: String, the new score of member (a double precision floating point number represented as String).


[View source]
def zinterstore(destination, keys : Array, weights = nil, aggregate = nil) #

Computes the intersection of numkeys sorted sets given by the specified keys, and stores the result in destination.

Options:

  • weights - nil or Array(String): Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set.
  • aggregate - With the AGGREGATE option, it is possible to specify how the results of the union are aggregated.

Return value: Integer, the number of elements in the resulting sorted set at destination.

Example:

redis.zinterstore("zset3", ["zset1", "zset2"], weights: [2, 3])

[View source]
def zlexcount(key, min, max) #

When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns the number of elements in the sorted set at key with a value between min and max.

Return value: Integer, the number of elements in the specified score range.


[View source]
def zrange(key, start, stop, with_scores = false) #

Returns the specified range of elements in the sorted set stored at key.

Options:

  • with_scores - true to return the scores of the elements together with the elements.

Return value: Array(String), list of elements in the specified range (optionally with their scores, in case the with_scores option is true).

Example:

redis.zrange("myzset", 0, -1, with_scores: true) # => ["one", "1", "uno", "1", "two", "2", "three", "3"]

[View source]
def zrangebylex(key, min, max, limit = nil) #

When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.

Options:

  • limit - an array of [offset, count]. Skip offset members, return a maximum of count members.

Return value:


[View source]
def zrangebyscore(key, min, max, limit = nil, with_scores = false) #

Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min).

Options:

  • limit - an array of [offset, count]. Skip offset members, return a maximum of count members.
  • with_scores - true to return the scores of the elements together with the elements.

Return value: Array(String), the list of elements in the specified score range (optionally with their scores).


[View source]
def zrank(key, member) #

Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high.

Return value:

  • If member exists in the sorted set, Integer: the rank of member.
  • If member does not exist in the sorted set or key does not exist: nil.

[View source]
def zrem(key, member) #

Removes the specified members from the sorted set stored at key.

Return value: Integer, the number of members removed from the sorted set, not including non existing members.


[View source]
def zremrangebylex(key, min, max) #

When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.

Return value: Integer, the number of elements removed.


[View source]
def zremrangebyrank(key, start, stop) #

Removes all elements in the sorted set stored at key with rank between start and stop.

Return value: Integer, the number of elements removed.


[View source]
def zremrangebyscore(key, start, stop) #

Removes all elements in the sorted set stored at key with a score between min and max (inclusive).

Return value: Integer, the number of elements removed.


[View source]
def zrevrange(key, start, stop, with_scores = false) #

Returns the specified range of elements in the sorted set stored at key.

Options:

  • with_scores - true to return the scores of the elements together with the elements.

Return value: Array(String), the list of elements in the specified range (optionally with their scores, in case the with_scores option is true).


[View source]
def zrevrangebylex(key, min, max, limit = nil) #

When all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering, this command returns all the elements in the sorted set at key with a value between min and max.

Options:

  • limit - an array of [offset, count]. Skip offset members, return a maximum of count members.

Return value:


[View source]
def zrevrangebyscore(key, min, max, limit = nil, with_scores = false) #

Returns all the elements in the sorted set at key with a score between max and min (including elements with score equal to max or min).

Options:

  • limit - an array of [offset, count]. Skip offset members, return a maximum of count members.
  • with_scores - true to return the scores of the elements together with the elements.

Return value: Array(String), the list of elements in the specified score range (optionally with their scores).


[View source]
def zrevrank(key, member) #

Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low.

Return value:

  • If member exists in the sorted set, Integer: the rank of member.
  • If member does not exist in the sorted set or key does not exist: nil.

[View source]
def zscan(key, cursor, match = nil, count = nil) #

The SCAN command and the closely related commands SSCAN, HSCAN and ZSCAN are used in order to incrementally iterate over a collection of elements.

Options:

  • match - It is possible to only iterate elements matching a given glob-style pattern, similarly to the behavior of the KEYS command that takes a pattern as only argument.
  • count - While SCAN does not provide guarantees about the number of elements returned at every iteration, it is possible to empirically adjust the behavior of SCAN using the COUNT option.

Return value: Array(String), contains two elements, a member and its associated score, for every returned element of the sorted set.

Example:

redis.zscan("myzset", 0)

[View source]
def zscore(key, member) #

Returns the score of member in the sorted set at key.

Return value: String, the score of member (a double precision floating point number).


[View source]
def zunionstore(destination, keys : Array, weights = nil, aggregate = nil) #

Computes the union of numkeys sorted sets given by the specified keys, and stores the result in destination.

Options:

  • weights - nil or Array(String): Using the WEIGHTS option, it is possible to specify a multiplication factor for each input sorted set.
  • aggregate - With the AGGREGATE option, it is possible to specify how the results of the union are aggregated.

Return value: Integer, the number of elements in the resulting sorted set at destination.


[View source]