module

Redis::Commands

Definition of all Redis commands except pipelining and transactions.

Instance methods

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")
Source
auth(password)

Request for authentication in a password-protected Redis server.

Return value: "OK"

Source
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)
Source
bitop(operation, key, keys : Array(String)) : Int64

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")
Source
bitop(operation, key, *keys : String) : Int64

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")
Source
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
Source
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"]
Source
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"]
Source
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)
Source
decr(key)

Decrements the number stored at key by one.

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

Source
decrby(key, decrement)

Decrements the number stored at key by decrement.

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

Source
del(keys : Array)

Removes the specified keys.

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

Example:

redis.del(["some", "keys", "to", "delete"])
Source
del(*keys)

Removes the specified keys.

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

Example:

redis.del("some", "keys", "to", "delete")
Source
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.

Source
echo(message)

Returns the given message.

Example:

redis.echo("Hello Redis") # => "Hello Redis"
Source
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: Depends on the executed script

Example:

redis.eval("return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", ["key1", "key2"], ["first art", "second arg"])
Source
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: Depends on the executed script

Source
exists(key)

Returns if key exists.

Return value:

  • 1 if the key exists.
  • 0 if the key does not exist.
Source
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)
Source
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.
Source
flushall

Flush all databases.

Return value: "OK"

Source
flushdb

Flush the current database.

Return value: "OK"

Source
geoadd(key, longitude, latitude, place)

Adds the specified geospatial items (latitude, longitude, name) to the specified key.

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

Source
geodist(key, member1, member2, unit = nil)

Return the distance between two members in the geospatial index represented by the sorted set.

Return value: String: returns the distance as a double (represented as a string) in the specified unit, or NULL if one or both the elements are missing

Source
geohash(key, *args)

Return valid Geohash strings representing the position of one or more elements in a sorted set value representing a geospatial index

Return value: Array(String): returns an array where each element is the Geohash corresponding to each member name passed as argument to the command

Source
geopos(key, *args)

Return the positions (longitude,latitude) of all the specified members of the geospatial index represented by the sorted set at key

Return value: Array(String): returns an array where each element is a two elements array representing longitude and latitude (x,y) of each member name passed as argument to the command

Source
georadius(key, longitude, latitude, radius, unit, withcoord = nil, withdist = nil, withhash = nil, count = nil, sort = nil)

Return the members of a sorted set populated with geospatial information using GEOADD, which are within the borders of the area specified with the center location and the maximum distance from the center (the radius).

Return value: Array(String): Returns a simple array or array of arrays, depending on the options passed https://redis.io/commands/georadius#return-value

Source
georadiusbymember(key, member, radius, unit, withcoord = nil, withdist = nil, withhash = nil, count = nil, sort = nil)

Exactly like GEORADIUS with the sole difference that instead of taking, as the center of the area to query, a longitude and latitude value, it takes the name of a member already existing inside the geospatial index represented by the sorted set

Return value: Array(String): Returns a simple array or array of arrays, depending on the options passed https://redis.io/commands/georadius#return-value

Source
geosearch(key, centerpoint : String | GeoCoordinate, shape : Int32 | String | GeoBox, unit, withcoord = nil, withdist = nil, withhash = nil, count = nil, sort = nil)

Return the members of a sorted set of geospatial information that are within the borders of the area specified from either a member of the set or a series of coordiates Replaces the deprecated GEORADIUS and GEORADIUSBYMEMBER commands.

Return value: Array(String): Returns a simple array or array of arrays, depending on the options passed https://redis.io/commands/geosearch#return-value

Source
get(key)

Get the value of key.

Return value: a String or nil

Example:

redis.set("foo", "test")
redis.get("foo") # => "test"
Source
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.

Source
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"
Source
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)
Source
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.

Source
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.
Source
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"
Source
hgetall(key)

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

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

Source
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
Source
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.

Source
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.

Source
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.

Source
hmget(key, fields : Array(String))

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

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

Source
hmget(key, *fields : String)

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

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

Source
hmset(key, hash)

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

Return value: "OK"

Source
hscan(key, cursor, match = nil, count = nil)
redis.hscan("myhash", 0)
redis.hscan("myhash", 0, "foo*")
redis.hscan("myhash", 0, "foo*", 1024)
Source
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")
Source
hset(key, hash : Hash)

Sets fields in the hash stored at keys to values.

Return value: Integer, specifically:

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

Example:

redis.hset("myhash", {"a" => "434", "b" => "435"})
Source
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.
Source
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.

Source
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
Source
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)
Source
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)
Source
info(section : String | Nil = nil)

The INFO command returns information and statistics about the server.

Return value: A hash with the server information

Source
keys(pattern)

Returns all keys matching pattern.

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

Example:

redis.keys("callmemaybe")
Source
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.

Source
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.

Source
llen(key)

Returns the length of the list stored at key.

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

Source
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")
Source
lpush(key, values : Array(RedisValue))

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.

Source
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.

Source
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.

Source
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)
Source
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")
Source
lset(key, index, value)

Sets the list element at index to value.

Return value: "OK"

Source
ltrim(key, start, stop)

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

Return value: "OK"

Source
mget(keys : Array(String)) : Array(RedisValue)
Source
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"]
Source
mset(hash : Hash)

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

Return value: "OK"

Example:

redis.mset({"foo1": "bar1", "foo2": "bar2"})
Source
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"})
Source
object_encoding(key)

Returns the kind of internal representation used in order to store the value associated with a key.

Return value: String: returns the kind of internal representation used in order to store the value associated with a key.

Source
object_idletime(key)

Returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations).

Return value: Integer: returns the number of seconds since the object stored at the specified key is idle (not requested by read or write operations).

Source
object_refcount(key)

Returns the number of references of the value associated with the specified key.

Return value: Integer: returns the number of references of the value associated with the specified key.

Source
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.
Source
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.
Source
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.
Source
pfadd(key, values : Array(String)) : Int64

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
Source
pfadd(key, *values : String) : Int64

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
Source
pfcount(keys : Array(String)) : Int64

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.

Source
pfcount(*keys : String) : Int64

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.

Source
pfmerge(keys : Array(String))

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.

Source
pfmerge(*keys : String)

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.

Source
ping

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

Example:

redis.ping # => "PONG"
Source
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"

Source
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.

Source
psubscribe(channel_patterns : Array(String))

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

Source
psubscribe(*channel_patterns)
Source
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.

Source
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")
Source
punsubscribe(channel_patterns : Array(String))

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

Source
punsubscribe(*channel_patterns)

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

Source
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"

Source
randomkey

Return a random key from the currently selected database.

Source
rename(old_key, new_key)

Renames old_key to newkey.

Return value: "OK"

Example:

redis.rename("old_name", "new_name")
Source
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")
Source
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.

Source
rpop(key)

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

Return value: "OK"

Source
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.

Source
rpush(key, values : Array(RedisValue))

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")
Source
rpush(key, *values : String)

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")
Source
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.

Source
sadd(key, values : Array(RedisValue))
Source
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.

Source
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)
redis.scan(0, "foo*")
redis.scan(0, "foo*", 1024)
Source
scard(key)

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

Source
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.

Source
script_flush

Flush the Lua scripts cache.

Return value: "OK"

Source
script_kill

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

Return value: "OK"

Source
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"
Source
sdiff(keys : Array(String)) : Array(RedisValue)

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.

Source
sdiff(*keys : String) : Array(RedisValue)
Source
sdiffstore(destination, keys : Array(String)) : Int64

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.

Source
sdiffstore(destination, *keys : String) : Int64

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.

Source
select(database_number : Int32 | Nil)

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

Return value: "OK"

Source
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)
Source
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)
Source
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")
Source
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
Source
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")
Source
sinter(keys : Array(String)) : Array(RedisValue)

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.

Source
sinter(*keys : String) : Array(RedisValue)

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.

Source
sinterstore(destination_key, keys : Array(String)) : Int64

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")
Source
sinterstore(destination_key, *keys : String) : Int64

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")
Source
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.
Source
smembers(key)

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

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

Source
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.
Source
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") # => [...]
Source
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.

Source
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.
Source
srem(key, values : Array(RedisValue))
Source
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")
Source
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)
redis.sscan("myset", 0, "foo*")
redis.sscan("myset", 0, "foo*", 1024)
Source
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.

Source
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
Source
subscribe(channels : Array(String)) : Void

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

Source
subscribe(*channels : String)

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

Source
sunion(keys : Array(String))

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.

Source
sunion(*keys : String)

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.

Source
sunionstore(destination, keys : Array(String)) : Int64

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.

Source
sunionstore(destination, *keys : String) : Int64

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.

Source
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).

Source
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"
Source
unsubscribe(channels : Array(String)) : Nil

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

Source
unsubscribe(*channels)

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

Source
unwatch

Flushes all the previously watched keys for a transaction.

Return value: "OK"

Source
watch(keys : Array(String))

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

Return value: "OK"

Source
watch(*keys)
Source
zadd(key, scores_and_members : Array(RedisValue), nx = false, xx = false, ch = false, incr = false)
Source
zadd(key, *scores_and_members, nx = false, xx = false, ch = false, incr = false)

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

Options:

  • Redis 3.0.2 or greater, ZADD supports a list of options, specified after the name of the key and before the first score argument. Options are:
  • xx -- Only update elements that already exist. Never add elements.
  • nx -- Don't update already existing elements. Always add new elements.
  • ch -- Modify the return value from the number of new elements added, to the total number of elements changed (CH is an abbreviation of changed). Changed elements are new elements added and elements already existing for which the score was updated. So elements specified in the command line having the same score as they had in the past are not counted. Note: normally the return value of ZADD only counts the number of new elements added.
  • incr -- When this option is specified ZADD acts like ZINCRBY. Only one score-element pair can be specified in this mode.

Return value:

Integer reply, specifically: The number of elements added to the sorted set, not including elements already existing for which the score was updated.

If the INCR option is specified, the return value will be Bulk string reply: The new score of member (a double precision floating point number) represented as string, or nil if the operation was aborted (when called with either the XX or the NX option).

Example:

redis.zadd("myzset", 1, "one")
redis.zadd("myzset", 2, "two", 3, "three")
redis.zadd("myzset", 4, "four", nx: true)
Source
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.

Source
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.

Source
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).

Source
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])
Source
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.

Source
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"]
Source
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:

Source
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).

Source
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.
Source
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.

Source
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.

Source
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.

Source
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.

Source
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).

Source
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:

Source
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).

Source
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.
Source
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)
redis.zscan("myzset", 0, "foo*")
redis.zscan("myzset", 0, "foo*", 1024)
Source
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).

Source
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.

Source

Nested types