Comredis v1.0.1 Comredis

Entry point module of the library with all Redis commands functions.

The functions defined here are loaded in compile time from the Redis commands documentation The only exceptions are commands/0, command_group/1 and command_groups/0 that provide a way to look for the desired commands. Because you don’t need to remember all of them by heart

Summary

Functions

Append a value to a key

Authenticate to the server

Asynchronously rewrite the append-only file

Asynchronously save the dataset to disk

Count set bits in a string

Perform bitwise operations between strings

Find first bit set or clear in a string

Remove and get the first element in a list, or block until one is available

Remove and get the last element in a list, or block until one is available

Pop a value from a list, push it to another list and return it; or block until one is available

Get the current connection name

Kill the connection of a client

Get the list of client connections

Stop processing commands from clients for some time

Instruct the server whether to reply to commands

Set the current connection name

Assign new hash slots to receiving node

Return the number of failure reports active for a given node

Return the number of local keys in the specified hash slot

Set hash slots as unbound in receiving node

Forces a slave to perform a manual failover of its master

Remove a node from the nodes table

Return local key names in the specified hash slot

Provides info about Redis Cluster node state

Returns the hash slot of the specified key

Force a node cluster to handshake with another node

Get Cluster config for the node

Reconfigure a node as a slave of the specified master node

Reset a Redis Cluster node

Forces the node to save cluster state on disk

Set the configuration epoch in a new node

Bind a hash slot to a specific node

List slave nodes of the specified master node

Get array of Cluster slot to node mappings

Get array of Redis command details

Get total number of Redis commands

Extract keys given a full Redis command

Returns the commands in the given command group

Returns the names of the command groups provided by Redis

Get array of specific Redis command details

Returns the list of all available commands

Get the value of a configuration parameter

Reset the stats returned by INFO

Rewrite the configuration file with the in memory configuration

Set a configuration parameter to the given value

Return the number of keys in the selected database

Get debugging information about a key

Make the server crash

Decrement the integer value of a key by one

Decrement the integer value of a key by the given number

Delete a key

Discard all commands issued after MULTI

Return a serialized version of the value stored at the specified key

Echo the given string

Execute a Lua script server side

Execute a Lua script server side

Execute all commands issued after MULTI

Determine if a key exists

Set a key’s time to live in seconds

Set the expiration for a key as a UNIX timestamp

Remove all keys from all databases

Remove all keys from the current database

Add one or more geospatial items in the geospatial index represented using a sorted set

Returns the distance between two members of a geospatial index

Returns members of a geospatial index as standard geohash strings

Returns longitude and latitude of members of a geospatial index

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member

Get the value of a key

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

Get a substring of the string stored at a key

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

Delete one or more hash fields

Determine if a hash field exists

Get the value of a hash field

Get all the fields and values in a hash

Increment the integer value of a hash field by the given number

Increment the float value of a hash field by the given amount

Get all the fields in a hash

Get the number of fields in a hash

Get the values of all the given hash fields

Set multiple hash fields to multiple values

Incrementally iterate hash fields and associated values

Set the string value of a hash field

Set the value of a hash field, only if the field does not exist

Get the length of the value of a hash field

Get all the values in a hash

Increment the integer value of a key by one

Increment the integer value of a key by the given amount

Increment the float value of a key by the given amount

Get information and statistics about the server

Find all keys matching the given pattern

Get the UNIX time stamp of the last successful save to disk

Get an element from a list by its index

Insert an element before or after another element in a list

Get the length of a list

Remove and get the first element in a list

Prepend one or multiple values to a list

Prepend a value to a list, only if the list exists

Get a range of elements from a list

Remove elements from a list

Set the value of an element in a list by its index

Trim a list to the specified range

Get the values of all the given keys

Atomically transfer a key from a Redis instance to another one

Listen for all requests received by the server in real time

Move a key to another database

Set multiple keys to multiple values

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

Mark the start of a transaction block

Inspect the internals of Redis objects

Remove the expiration from a key

Set a key’s time to live in milliseconds

Set the expiration for a key as a UNIX timestamp specified in milliseconds

Adds the specified elements to the specified HyperLogLog

Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s)

Merge N different HyperLogLogs into a single one

Ping the server

Set the value and expiration in milliseconds of a key

Listen for messages published to channels matching the given patterns

Get the time to live for a key in milliseconds

Post a message to a channel

Inspect the state of the Pub/Sub subsystem

Stop listening for messages posted to channels matching the given patterns

Close the connection

Return a random key from the keyspace

Enables read queries for a connection to a cluster slave node

Disables read queries for a connection to a cluster slave node

Rename a key

Rename a key, only if the new key does not exist

Create a key using the provided serialized value, previously obtained using DUMP

Return the role of the instance in the context of replication

Remove and get the last element in a list

Remove the last element in a list, prepend it to another list and return it

Append one or multiple values to a list

Append a value to a list, only if the list exists

Add one or more members to a set

Synchronously save the dataset to disk

Incrementally iterate the keys space

Get the number of members in a set

Set the debug mode for executed scripts

Check existence of scripts in the script cache

Remove all the scripts from the script cache

Kill the script currently in execution

Load the specified Lua script into the script cache

Subtract multiple sets

Subtract multiple sets and store the resulting set in a key

Change the selected database for the current connection

Set the string value of a key

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

Set the value and expiration of a key

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

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

Synchronously save the dataset to disk and then shut down the server

Intersect multiple sets

Intersect multiple sets and store the resulting set in a key

Determine if a given value is a member of a set

Make the server a slave of another instance, or promote it as master

Manages the Redis slow queries log

Get all the members in a set

Move a member from one set to another

Sort the elements in a list, set or sorted set

Remove and return one or multiple random members from a set

Get one or multiple random members from a set

Remove one or more members from a set

Incrementally iterate Set elements

Get the length of the value stored in a key

Listen for messages published to the given channels

Add multiple sets

Add multiple sets and store the resulting set in a key

Internal command used for replication

Return the current server time

Get the time to live for a key

Determine the type stored at key

Stop listening for messages posted to the given channels

Forget about all watched keys

Wait for the synchronous replication of all the write commands sent in the context of the current connection

Watch the given keys to determine execution of the MULTI/EXEC block

Add one or more members to a sorted set, or update its score if it already exists

Get the number of members in a sorted set

Count the members in a sorted set with scores within the given values

Increment the score of a member in a sorted set

Intersect multiple sorted sets and store the resulting sorted set in a new key

Count the number of members in a sorted set between a given lexicographical range

Return a range of members in a sorted set, by index

Return a range of members in a sorted set, by lexicographical range

Return a range of members in a sorted set, by score

Determine the index of a member in a sorted set

Remove one or more members from a sorted set

Remove all members in a sorted set between the given lexicographical range

Remove all members in a sorted set within the given indexes

Remove all members in a sorted set within the given scores

Return a range of members in a sorted set, by index, with scores ordered from high to low

Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings

Return a range of members in a sorted set, by score, with scores ordered from high to low

Determine the index of a member in a sorted set, with scores ordered from high to low

Incrementally iterate sorted sets elements and associated scores

Get the score associated with the given member in a sorted set

Add multiple sorted sets and store the resulting sorted set in a new key

Functions

append(key, value)

Append a value to a key

Group: string

Available since version 2.0.0.

Time complexity: 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.

Arguments:

  • key

  • value string
auth(password)

Authenticate to the server

Group: connection

Available since version 1.0.0.

Arguments:

  • password string
bgrewriteaof()

Asynchronously rewrite the append-only file

Group: server

Available since version 1.0.0.

bgsave()

Asynchronously save the dataset to disk

Group: server

Available since version 1.0.0.

bitcount(key, opts \\ [])

Count set bits in a string

Group: string

Available since version 2.6.0.

Time complexity: O(N)

Arguments:

  • key

  • start_end optional, [integer, integer]
bitop(operation, destkey, key)

Perform bitwise operations between strings

Group: string

Available since version 2.6.0.

Time complexity: O(N)

Arguments:

  • operation string

  • destkey key

  • key multiple
bitpos(key, bit, opts \\ [])

Find first bit set or clear in a string

Group: string

Available since version 2.8.7.

Time complexity: O(N)

Arguments:

  • key

  • bit integer

  • start optional, integer

  • end optional, integer
blpop(key, timeout)

Remove and get the first element in a list, or block until one is available

Group: list

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key multiple

  • timeout integer
brpop(key, timeout)

Remove and get the last element in a list, or block until one is available

Group: list

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key multiple

  • timeout integer
brpoplpush(source, destination, timeout)

Pop a value from a list, push it to another list and return it; or block until one is available

Group: list

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • source key

  • destination key

  • timeout integer
client_getname()

Get the current connection name

Group: server

Available since version 2.6.9.

Time complexity: O(1)

client_kill(opts \\ [])

Kill the connection of a client

Group: server

Available since version 2.4.0.

Time complexity: O(N) where N is the number of client connections

Arguments:

  • ip_port optional, string

  • id optional, integer

  • type optional, enum, ["normal", "master", "slave", "pubsub"]

  • addr optional, string

  • skipme optional, string
client_list()

Get the list of client connections

Group: server

Available since version 2.4.0.

Time complexity: O(N) where N is the number of client connections

client_pause(timeout)

Stop processing commands from clients for some time

Group: server

Available since version 2.9.50.

Time complexity: O(1)

Arguments:

  • timeout integer
client_reply(reply_mode)

Instruct the server whether to reply to commands

Group: server

Available since version 3.2.

Time complexity: O(1)

Arguments:

  • reply_mode enum, ["ON", "OFF", "SKIP"]
client_setname(connection_name)

Set the current connection name

Group: server

Available since version 2.6.9.

Time complexity: O(1)

Arguments:

  • connection_name string
cluster_addslots(slot)

Assign new hash slots to receiving node

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the total number of hash slot arguments

Arguments:

  • slot multiple, integer
cluster_count_failure_reports(node_id)

Return the number of failure reports active for a given node

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the number of failure reports

Arguments:

  • node_id string
cluster_countkeysinslot(slot)

Return the number of local keys in the specified hash slot

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • slot integer
cluster_delslots(slot)

Set hash slots as unbound in receiving node

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the total number of hash slot arguments

Arguments:

  • slot multiple, integer
cluster_failover(opts \\ [])

Forces a slave to perform a manual failover of its master.

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • options optional, enum, ["FORCE", "TAKEOVER"]
cluster_forget(node_id)

Remove a node from the nodes table

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • node_id string
cluster_getkeysinslot(slot, count)

Return local key names in the specified hash slot

Group: cluster

Available since version 3.0.0.

Time complexity: O(log(N)) where N is the number of requested keys

Arguments:

  • slot integer

  • count integer
cluster_info()

Provides info about Redis Cluster node state

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

cluster_keyslot(key)

Returns the hash slot of the specified key

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the number of bytes in the key

Arguments:

  • key string
cluster_meet(ip, port)

Force a node cluster to handshake with another node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • ip string

  • port integer
cluster_nodes()

Get Cluster config for the node

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the total number of Cluster nodes

cluster_replicate(node_id)

Reconfigure a node as a slave of the specified master node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • node_id string
cluster_reset(opts \\ [])

Reset a Redis Cluster node

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the number of known nodes. The command may execute a FLUSHALL as a side effect.

Arguments:

  • reset_type optional, enum, ["HARD", "SOFT"]
cluster_saveconfig()

Forces the node to save cluster state on disk

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

cluster_set_config_epoch(config_epoch)

Set the configuration epoch in a new node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • config_epoch integer
cluster_setslot(slot, subcommand, opts \\ [])

Bind a hash slot to a specific node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • slot integer

  • subcommand enum, ["IMPORTING", "MIGRATING", "STABLE", "NODE"]

  • node_id optional, string
cluster_slaves(node_id)

List slave nodes of the specified master node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • node_id string
cluster_slots()

Get array of Cluster slot to node mappings

Group: cluster

Available since version 3.0.0.

Time complexity: O(N) where N is the total number of Cluster nodes

command()

Get array of Redis command details

Group: server

Available since version 2.8.13.

Time complexity: O(N) where N is the total number of Redis commands

command_count()

Get total number of Redis commands

Group: server

Available since version 2.8.13.

Time complexity: O(1)

command_getkeys()

Extract keys given a full Redis command

Group: server

Available since version 2.8.13.

Time complexity: O(N) where N is the number of arguments to the command

command_group(group)

Specs

command_group(atom) :: [atom]

Returns the commands in the given command group.

command_groups()

Specs

command_groups :: [atom]

Returns the names of the command groups provided by Redis.

command_info(command_name)

Get array of specific Redis command details

Group: server

Available since version 2.8.13.

Time complexity: O(N) when N is number of commands to look up

Arguments:

  • command_name multiple, string
commands()

Specs

commands :: [atom]

Returns the list of all available commands.

config_get(parameter)

Get the value of a configuration parameter

Group: server

Available since version 2.0.0.

Arguments:

  • parameter string
config_resetstat()

Reset the stats returned by INFO

Group: server

Available since version 2.0.0.

Time complexity: O(1)

config_rewrite()

Rewrite the configuration file with the in memory configuration

Group: server

Available since version 2.8.0.

config_set(parameter, value)

Set a configuration parameter to the given value

Group: server

Available since version 2.0.0.

Arguments:

  • parameter string

  • value string
dbsize()

Return the number of keys in the selected database

Group: server

Available since version 1.0.0.

debug_object(key)

Get debugging information about a key

Group: server

Available since version 1.0.0.

Arguments:

  • key
debug_segfault()

Make the server crash

Group: server

Available since version 1.0.0.

decr(key)

Decrement the integer value of a key by one

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
decrby(key, decrement)

Decrement the integer value of a key by the given number

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • decrement integer
del(key)

Delete a key

Group: generic

Available since version 1.0.0.

Time complexity: O(N) where N is the number of keys that will be removed. When a key to remove holds a value other than a string, the individual complexity for this key is O(M) where M is the number of elements in the list, set, sorted set or hash. Removing a single key that holds a string value is O(1).

Arguments:

  • key multiple
discard()

Discard all commands issued after MULTI

Group: transactions

Available since version 2.0.0.

dump(key)

Return a serialized version of the value stored at the specified key.

Group: generic

Available since version 2.6.0.

Time complexity: O(1) to access the key and additional O(NM) to serialized it, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1M) where M is small, so simply O(1).

Arguments:

  • key
echo(message)

Echo the given string

Group: connection

Available since version 1.0.0.

Arguments:

  • message string
eval(script, numkeys, key, arg)

Execute a Lua script server side

Group: scripting

Available since version 2.6.0.

Time complexity: Depends on the script that is executed.

Arguments:

  • script string

  • numkeys integer

  • key multiple

  • arg multiple, string
evalsha(sha1, numkeys, key, arg)

Execute a Lua script server side

Group: scripting

Available since version 2.6.0.

Time complexity: Depends on the script that is executed.

Arguments:

  • sha1 string

  • numkeys integer

  • key multiple

  • arg multiple, string
exec()

Execute all commands issued after MULTI

Group: transactions

Available since version 1.2.0.

exists(key)

Determine if a key exists

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key multiple
expire(key, seconds)

Set a key’s time to live in seconds

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • seconds integer
expireat(key, timestamp)

Set the expiration for a key as a UNIX timestamp

Group: generic

Available since version 1.2.0.

Time complexity: O(1)

Arguments:

  • key

  • timestamp posix time
flushall()

Remove all keys from all databases

Group: server

Available since version 1.0.0.

flushdb()

Remove all keys from the current database

Group: server

Available since version 1.0.0.

geoadd(key, longitude_latitude_member)

Add one or more geospatial items in the geospatial index represented using a sorted set

Group: geo

Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.

Arguments:

  • key

  • longitude_latitude_member multiple, [double, double, string]
geodist(key, member1, member2, opts \\ [])

Returns the distance between two members of a geospatial index

Group: geo

Time complexity: O(log(N))

Arguments:

  • key

  • member1 string

  • member2 string

  • unit optional, string
geohash(key, member)

Returns members of a geospatial index as standard geohash strings

Group: geo

Time complexity: O(log(N)) for each member requested, where N is the number of elements in the sorted set.

Arguments:

  • key

  • member multiple, string
geopos(key, member)

Returns longitude and latitude of members of a geospatial index

Group: geo

Time complexity: O(log(N)) for each member requested, where N is the number of elements in the sorted set.

Arguments:

  • key

  • member multiple, string
georadius(key, longitude, latitude, radius, unit, opts \\ [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point

Group: geo

Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.

Arguments:

  • key

  • longitude double

  • latitude double

  • radius double

  • unit enum, ["m", "km", "ft", "mi"]

  • withcoord optional, enum, ["WITHCOORD"]

  • withdist optional, enum, ["WITHDIST"]

  • withhash optional, enum, ["WITHHASH"]

  • count optional, integer
georadiusbymember(key, member, radius, unit, opts \\ [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member

Group: geo

Time complexity: O(N+log(M)) where N is the number of elements inside the bounding box of the circular area delimited by center and radius and M is the number of items inside the index.

Arguments:

  • key

  • member string

  • radius double

  • unit enum, ["m", "km", "ft", "mi"]

  • withcoord optional, enum, ["WITHCOORD"]

  • withdist optional, enum, ["WITHDIST"]

  • withhash optional, enum, ["WITHHASH"]

  • count optional, integer
get(key)

Get the value of a key

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
getbit(key, offset)

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

Group: string

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key

  • offset integer
getrange(key, start, end)

Get a substring of the string stored at a key

Group: string

Available since version 2.4.0.

Time complexity: 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.

Arguments:

  • key

  • start integer

  • end integer
getset(key, value)

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

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • value string
hdel(key, field)

Delete one or more hash fields

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the number of fields to be removed.

Arguments:

  • key

  • field multiple, string
hexists(key, field)

Determine if a hash field exists

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • field string
hget(key, field)

Get the value of a hash field

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • field string
hgetall(key)

Get all the fields and values in a hash

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the size of the hash.

Arguments:

  • key
hincrby(key, field, increment)

Increment the integer value of a hash field by the given number

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • field string

  • increment integer
hincrbyfloat(key, field, increment)

Increment the float value of a hash field by the given amount

Group: hash

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key

  • field string

  • increment double
hkeys(key)

Get all the fields in a hash

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the size of the hash.

Arguments:

  • key
hlen(key)

Get the number of fields in a hash

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key
hmget(key, field)

Get the values of all the given hash fields

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the number of fields being requested.

Arguments:

  • key

  • field multiple, string
hmset(key, field_value)

Set multiple hash fields to multiple values

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the number of fields being set.

Arguments:

  • key

  • field_value multiple, [string, string]
hscan(key, cursor, opts \\ [])

Incrementally iterate hash fields and associated values

Group: hash

Available since version 2.8.0.

Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..

Arguments:

  • key

  • cursor integer

  • match optional

  • count optional, integer
hset(key, field, value)

Set the string value of a hash field

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • field string

  • value string
hsetnx(key, field, value)

Set the value of a hash field, only if the field does not exist

Group: hash

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • field string

  • value string
hstrlen(key, field)

Get the length of the value of a hash field

Group: hash

Available since version 3.2.0.

Time complexity: O(1)

Arguments:

  • key

  • field string
hvals(key)

Get all the values in a hash

Group: hash

Available since version 2.0.0.

Time complexity: O(N) where N is the size of the hash.

Arguments:

  • key
incr(key)

Increment the integer value of a key by one

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
incrby(key, increment)

Increment the integer value of a key by the given amount

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • increment integer
incrbyfloat(key, increment)

Increment the float value of a key by the given amount

Group: string

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key

  • increment double
info(opts \\ [])

Get information and statistics about the server

Group: server

Available since version 1.0.0.

Arguments:

  • section optional, string
keys(pattern)

Find all keys matching the given pattern

Group: generic

Available since version 1.0.0.

Time complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.

Arguments:

  • pattern
lastsave()

Get the UNIX time stamp of the last successful save to disk

Group: server

Available since version 1.0.0.

lindex(key, index)

Get an element from a list by its index

Group: list

Available since version 1.0.0.

Time complexity: O(N) where N is the number of elements to traverse to get to the element at index. This makes asking for the first or the last element of the list O(1).

Arguments:

  • key

  • index integer
linsert(key, where, pivot, value)

Insert an element before or after another element in a list

Group: list

Available since version 2.2.0.

Time complexity: O(N) where N is the number of elements to traverse before seeing the value pivot. This means that inserting somewhere on the left end on the list (head) can be considered O(1) and inserting somewhere on the right end (tail) is O(N).

Arguments:

  • key

  • where enum, ["BEFORE", "AFTER"]

  • pivot string

  • value string
llen(key)

Get the length of a list

Group: list

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
lpop(key)

Remove and get the first element in a list

Group: list

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
lpush(key, value)

Prepend one or multiple values to a list

Group: list

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • value multiple, string
lpushx(key, value)

Prepend a value to a list, only if the list exists

Group: list

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key

  • value string
lrange(key, start, stop)

Get a range of elements from a list

Group: list

Available since version 1.0.0.

Time complexity: O(S+N) where S is the distance of start offset from HEAD for small lists, from nearest end (HEAD or TAIL) for large lists; and N is the number of elements in the specified range.

Arguments:

  • key

  • start integer

  • stop integer
lrem(key, count, value)

Remove elements from a list

Group: list

Available since version 1.0.0.

Time complexity: O(N) where N is the length of the list.

Arguments:

  • key

  • count integer

  • value string
lset(key, index, value)

Set the value of an element in a list by its index

Group: list

Available since version 1.0.0.

Time complexity: O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1).

Arguments:

  • key

  • index integer

  • value string
ltrim(key, start, stop)

Trim a list to the specified range

Group: list

Available since version 1.0.0.

Time complexity: O(N) where N is the number of elements to be removed by the operation.

Arguments:

  • key

  • start integer

  • stop integer
mget(key)

Get the values of all the given keys

Group: string

Available since version 1.0.0.

Time complexity: O(N) where N is the number of keys to retrieve.

Arguments:

  • key multiple
migrate(host, port, key, destination_db, timeout, opts \\ [])

Atomically transfer a key from a Redis instance to another one.

Group: generic

Available since version 2.6.0.

Time complexity: This command actually executes a DUMP+DEL in the source instance, and a RESTORE in the target instance. See the pages of these commands for time complexity. Also an O(N) data transfer between the two instances is performed.

Arguments:

  • host string

  • port string

  • key enum, ["key", "\"\""]

  • destination_db integer

  • timeout integer

  • copy optional, enum, ["COPY"]

  • replace optional, enum, ["REPLACE"]

  • keys optional
monitor()

Listen for all requests received by the server in real time

Group: server

Available since version 1.0.0.

move(key, db)

Move a key to another database

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • db integer
mset(key_value)

Set multiple keys to multiple values

Group: string

Available since version 1.0.1.

Time complexity: O(N) where N is the number of keys to set.

Arguments:

  • key_value multiple, [key, string]
msetnx(key_value)

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

Group: string

Available since version 1.0.1.

Time complexity: O(N) where N is the number of keys to set.

Arguments:

  • key_value multiple, [key, string]
multi()

Mark the start of a transaction block

Group: transactions

Available since version 1.2.0.

object(subcommand, opts \\ [])

Inspect the internals of Redis objects

Group: generic

Available since version 2.2.3.

Time complexity: O(1) for all the currently implemented subcommands.

Arguments:

  • subcommand string

  • arguments optional, multiple, string
persist(key)

Remove the expiration from a key

Group: generic

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key
pexpire(key, milliseconds)

Set a key’s time to live in milliseconds

Group: generic

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key

  • milliseconds integer
pexpireat(key, milliseconds_timestamp)

Set the expiration for a key as a UNIX timestamp specified in milliseconds

Group: generic

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key

  • milliseconds_timestamp posix time
pfadd(key, element)

Adds the specified elements to the specified HyperLogLog.

Group: hyperloglog

Available since version 2.8.9.

Time complexity: O(1) to add every element.

Arguments:

  • key

  • element multiple, string
pfcount(key)

Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).

Group: hyperloglog

Available since version 2.8.9.

Time complexity: O(1) with every small average constant times when called with a single key. O(N) with N being the number of keys, and much bigger constant times, when called with multiple keys.

Arguments:

  • key multiple
pfmerge(destkey, sourcekey)

Merge N different HyperLogLogs into a single one.

Group: hyperloglog

Available since version 2.8.9.

Time complexity: O(N) to merge N HyperLogLogs, but with high constant times.

Arguments:

  • destkey key

  • sourcekey multiple, key
ping()

Ping the server

Group: connection

Available since version 1.0.0.

psetex(key, milliseconds, value)

Set the value and expiration in milliseconds of a key

Group: string

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key

  • milliseconds integer

  • value string
psubscribe(pattern)

Listen for messages published to channels matching the given patterns

Group: pubsub

Available since version 2.0.0.

Time complexity: O(N) where N is the number of patterns the client is already subscribed to.

Arguments:

  • pattern multiple
pttl(key)

Get the time to live for a key in milliseconds

Group: generic

Available since version 2.6.0.

Time complexity: O(1)

Arguments:

  • key
publish(channel, message)

Post a message to a channel

Group: pubsub

Available since version 2.0.0.

Time complexity: O(N+M) where N is the number of clients subscribed to the receiving channel and M is the total number of subscribed patterns (by any client).

Arguments:

  • channel string

  • message string
pubsub(subcommand, opts \\ [])

Inspect the state of the Pub/Sub subsystem

Group: pubsub

Available since version 2.8.0.

Time complexity: O(N) for the CHANNELS subcommand, where N is the number of active channels, and assuming constant time pattern matching (relatively short channels and patterns). O(N) for the NUMSUB subcommand, where N is the number of requested channels. O(1) for the NUMPAT subcommand.

Arguments:

  • subcommand string

  • argument optional, multiple, string
punsubscribe(opts \\ [])

Stop listening for messages posted to channels matching the given patterns

Group: pubsub

Available since version 2.0.0.

Time complexity: O(N+M) where N is the number of patterns the client is already subscribed and M is the number of total patterns subscribed in the system (by any client).

Arguments:

  • pattern optional, multiple
quit()

Close the connection

Group: connection

Available since version 1.0.0.

randomkey()

Return a random key from the keyspace

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

readonly()

Enables read queries for a connection to a cluster slave node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

readwrite()

Disables read queries for a connection to a cluster slave node

Group: cluster

Available since version 3.0.0.

Time complexity: O(1)

rename(key, newkey)

Rename a key

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • newkey key
renamenx(key, newkey)

Rename a key, only if the new key does not exist

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • newkey key
restore(key, ttl, serialized_value, opts \\ [])

Create a key using the provided serialized value, previously obtained using DUMP.

Group: generic

Available since version 2.6.0.

Time complexity: O(1) to create the new key and additional O(NM) to reconstruct the serialized value, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1M) where M is small, so simply O(1). However for sorted set values the complexity is O(NMlog(N)) because inserting values into sorted sets is O(log(N)).

Arguments:

  • key

  • ttl integer

  • serialized_value string

  • replace optional, enum, ["REPLACE"]
role()

Return the role of the instance in the context of replication

Group: server

Available since version 2.8.12.

rpop(key)

Remove and get the last element in a list

Group: list

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
rpoplpush(source, destination)

Remove the last element in a list, prepend it to another list and return it

Group: list

Available since version 1.2.0.

Time complexity: O(1)

Arguments:

  • source key

  • destination key
rpush(key, value)

Append one or multiple values to a list

Group: list

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • value multiple, string
rpushx(key, value)

Append a value to a list, only if the list exists

Group: list

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key

  • value string
sadd(key, member)

Add one or more members to a set

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the number of members to be added.

Arguments:

  • key

  • member multiple, string
save()

Synchronously save the dataset to disk

Group: server

Available since version 1.0.0.

scan(cursor, opts \\ [])

Incrementally iterate the keys space

Group: generic

Available since version 2.8.0.

Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.

Arguments:

  • cursor integer

  • match optional

  • count optional, integer
scard(key)

Get the number of members in a set

Group: set

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
script_debug(mode)

Set the debug mode for executed scripts.

Group: scripting

Available since version 3.2.0.

Time complexity: O(1)

Arguments:

  • mode enum, ["YES", "SYNC", "NO"]
script_exists(script)

Check existence of scripts in the script cache.

Group: scripting

Available since version 2.6.0.

Time complexity: O(N) with N being the number of scripts to check (so checking a single script is an O(1) operation).

Arguments:

  • script multiple, string
script_flush()

Remove all the scripts from the script cache.

Group: scripting

Available since version 2.6.0.

Time complexity: O(N) with N being the number of scripts in cache

script_kill()

Kill the script currently in execution.

Group: scripting

Available since version 2.6.0.

Time complexity: O(1)

script_load(script)

Load the specified Lua script into the script cache.

Group: scripting

Available since version 2.6.0.

Time complexity: O(N) with N being the length in bytes of the script body.

Arguments:

  • script string
sdiff(key)

Subtract multiple sets

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the total number of elements in all given sets.

Arguments:

  • key multiple
sdiffstore(destination, key)

Subtract multiple sets and store the resulting set in a key

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the total number of elements in all given sets.

Arguments:

  • destination key

  • key multiple
select(index)

Change the selected database for the current connection

Group: connection

Available since version 1.0.0.

Arguments:

  • index integer
set(key, value, opts \\ [])

Set the string value of a key

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • value string

  • ex optional, integer

  • px optional, integer

  • condition optional, enum, ["NX", "XX"]
setbit(key, offset, value)

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

Group: string

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key

  • offset integer

  • value string
setex(key, seconds, value)

Set the value and expiration of a key

Group: string

Available since version 2.0.0.

Time complexity: O(1)

Arguments:

  • key

  • seconds integer

  • value string
setnx(key, value)

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

Group: string

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • value string
setrange(key, offset, value)

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

Group: string

Available since version 2.2.0.

Time complexity: 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.

Arguments:

  • key

  • offset integer

  • value string
shutdown(opts \\ [])

Synchronously save the dataset to disk and then shut down the server

Group: server

Available since version 1.0.0.

Arguments:

  • save_mode optional, enum, ["NOSAVE", "SAVE"]
sinter(key)

Intersect multiple sets

Group: set

Available since version 1.0.0.

Time complexity: O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.

Arguments:

  • key multiple
sinterstore(destination, key)

Intersect multiple sets and store the resulting set in a key

Group: set

Available since version 1.0.0.

Time complexity: O(N*M) worst case where N is the cardinality of the smallest set and M is the number of sets.

Arguments:

  • destination key

  • key multiple
sismember(key, member)

Determine if a given value is a member of a set

Group: set

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • member string
slaveof(host, port)

Make the server a slave of another instance, or promote it as master

Group: server

Available since version 1.0.0.

Arguments:

  • host string

  • port string
slowlog(subcommand, opts \\ [])

Manages the Redis slow queries log

Group: server

Available since version 2.2.12.

Arguments:

  • subcommand string

  • argument optional, string
smembers(key)

Get all the members in a set

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the set cardinality.

Arguments:

  • key
smove(source, destination, member)

Move a member from one set to another

Group: set

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • source key

  • destination key

  • member string
sort(key, opts \\ [])

Sort the elements in a list, set or sorted set

Group: generic

Available since version 1.0.0.

Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is currently O(N) as there is a copy step that will be avoided in next releases.

Arguments:

  • key

  • by optional

  • limit optional, [integer, integer]

  • get optional, multiple, string

  • order optional, enum, ["ASC", "DESC"]

  • sorting optional, enum, ["ALPHA"]

  • store optional, key
spop(key, opts \\ [])

Remove and return one or multiple random members from a set

Group: set

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key

  • count optional, integer
srandmember(key, opts \\ [])

Get one or multiple random members from a set

Group: set

Available since version 1.0.0.

Time complexity: Without the count argument O(1), otherwise O(N) where N is the absolute value of the passed count.

Arguments:

  • key

  • count optional, integer
srem(key, member)

Remove one or more members from a set

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the number of members to be removed.

Arguments:

  • key

  • member multiple, string
sscan(key, cursor, opts \\ [])

Incrementally iterate Set elements

Group: set

Available since version 2.8.0.

Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..

Arguments:

  • key

  • cursor integer

  • match optional

  • count optional, integer
strlen(key)

Get the length of the value stored in a key

Group: string

Available since version 2.2.0.

Time complexity: O(1)

Arguments:

  • key
subscribe(channel)

Listen for messages published to the given channels

Group: pubsub

Available since version 2.0.0.

Time complexity: O(N) where N is the number of channels to subscribe to.

Arguments:

  • channel multiple, [string]
sunion(key)

Add multiple sets

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the total number of elements in all given sets.

Arguments:

  • key multiple
sunionstore(destination, key)

Add multiple sets and store the resulting set in a key

Group: set

Available since version 1.0.0.

Time complexity: O(N) where N is the total number of elements in all given sets.

Arguments:

  • destination key

  • key multiple
sync()

Internal command used for replication

Group: server

Available since version 1.0.0.

time()

Return the current server time

Group: server

Available since version 2.6.0.

Time complexity: O(1)

ttl(key)

Get the time to live for a key

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
type(key)

Determine the type stored at key

Group: generic

Available since version 1.0.0.

Time complexity: O(1)

Arguments:

  • key
unsubscribe(opts \\ [])

Stop listening for messages posted to the given channels

Group: pubsub

Available since version 2.0.0.

Time complexity: O(N) where N is the number of clients already subscribed to a channel.

Arguments:

  • channel optional, multiple, string
unwatch()

Forget about all watched keys

Group: transactions

Available since version 2.2.0.

Time complexity: O(1)

wait(numslaves, timeout)

Wait for the synchronous replication of all the write commands sent in the context of the current connection

Group: generic

Available since version 3.0.0.

Time complexity: O(1)

Arguments:

  • numslaves integer

  • timeout integer
watch(key)

Watch the given keys to determine execution of the MULTI/EXEC block

Group: transactions

Available since version 2.2.0.

Time complexity: O(1) for every key.

Arguments:

  • key multiple
zadd(key, score_member, opts \\ [])

Add one or more members to a sorted set, or update its score if it already exists

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(log(N)) for each item added, where N is the number of elements in the sorted set.

Arguments:

  • key

  • condition optional, enum, ["NX", "XX"]

  • change optional, enum, ["CH"]

  • increment optional, enum, ["INCR"]

  • score_member multiple, [double, string]
zcard(key)

Get the number of members in a sorted set

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(1)

Arguments:

  • key
zcount(key, min, max)

Count the members in a sorted set with scores within the given values

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(log(N)) with N being the number of elements in the sorted set.

Arguments:

  • key

  • min double

  • max double
zincrby(key, increment, member)

Increment the score of a member in a sorted set

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(log(N)) where N is the number of elements in the sorted set.

Arguments:

  • key

  • increment integer

  • member string
zinterstore(destination, numkeys, key, opts \\ [])

Intersect multiple sorted sets and store the resulting sorted set in a new key

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(NK)+O(Mlog(M)) worst case with N being the smallest input sorted set, K being the number of input sorted sets and M being the number of elements in the resulting sorted set.

Arguments:

  • destination key

  • numkeys integer

  • key multiple

  • weights optional, integer

  • aggregate optional, enum, ["SUM", "MIN", "MAX"]
zlexcount(key, min, max)

Count the number of members in a sorted set between a given lexicographical range

Group: sorted_set

Available since version 2.8.9.

Time complexity: O(log(N)) with N being the number of elements in the sorted set.

Arguments:

  • key

  • min string

  • max string
zrange(key, start, stop, opts \\ [])

Return a range of members in a sorted set, by index

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.

Arguments:

  • key

  • start integer

  • stop integer

  • withscores optional, enum, ["WITHSCORES"]
zrangebylex(key, min, max, opts \\ [])

Return a range of members in a sorted set, by lexicographical range

Group: sorted_set

Available since version 2.8.9.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

Arguments:

  • key

  • min string

  • max string

  • limit optional, [integer, integer]
zrangebyscore(key, min, max, opts \\ [])

Return a range of members in a sorted set, by score

Group: sorted_set

Available since version 1.0.5.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

Arguments:

  • key

  • min double

  • max double

  • withscores optional, enum, ["WITHSCORES"]

  • limit optional, [integer, integer]
zrank(key, member)

Determine the index of a member in a sorted set

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(log(N))

Arguments:

  • key

  • member string
zrem(key, member)

Remove one or more members from a sorted set

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(M*log(N)) with N being the number of elements in the sorted set and M the number of elements to be removed.

Arguments:

  • key

  • member multiple, string
zremrangebylex(key, min, max)

Remove all members in a sorted set between the given lexicographical range

Group: sorted_set

Available since version 2.8.9.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

Arguments:

  • key

  • min string

  • max string
zremrangebyrank(key, start, stop)

Remove all members in a sorted set within the given indexes

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

Arguments:

  • key

  • start integer

  • stop integer
zremrangebyscore(key, min, max)

Remove all members in a sorted set within the given scores

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements removed by the operation.

Arguments:

  • key

  • min double

  • max double
zrevrange(key, start, stop, opts \\ [])

Return a range of members in a sorted set, by index, with scores ordered from high to low

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.

Arguments:

  • key

  • start integer

  • stop integer

  • withscores optional, enum, ["WITHSCORES"]
zrevrangebylex(key, max, min, opts \\ [])

Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.

Group: sorted_set

Available since version 2.8.9.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

Arguments:

  • key

  • max string

  • min string

  • limit optional, [integer, integer]
zrevrangebyscore(key, max, min, opts \\ [])

Return a range of members in a sorted set, by score, with scores ordered from high to low

Group: sorted_set

Available since version 2.2.0.

Time complexity: O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned. If M is constant (e.g. always asking for the first 10 elements with LIMIT), you can consider it O(log(N)).

Arguments:

  • key

  • max double

  • min double

  • withscores optional, enum, ["WITHSCORES"]

  • limit optional, [integer, integer]
zrevrank(key, member)

Determine the index of a member in a sorted set, with scores ordered from high to low

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(log(N))

Arguments:

  • key

  • member string
zscan(key, cursor, opts \\ [])

Incrementally iterate sorted sets elements and associated scores

Group: sorted_set

Available since version 2.8.0.

Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection..

Arguments:

  • key

  • cursor integer

  • match optional

  • count optional, integer
zscore(key, member)

Get the score associated with the given member in a sorted set

Group: sorted_set

Available since version 1.2.0.

Time complexity: O(1)

Arguments:

  • key

  • member string
zunionstore(destination, numkeys, key, opts \\ [])

Add multiple sorted sets and store the resulting sorted set in a new key

Group: sorted_set

Available since version 2.0.0.

Time complexity: O(N)+O(M log(M)) with N being the sum of the sizes of the input sorted sets, and M being the number of elements in the resulting sorted set.

Arguments:

  • destination key

  • numkeys integer

  • key multiple

  • weights optional, integer

  • aggregate optional, enum, ["SUM", "MIN", "MAX"]