Redis Commands CheatSheet
-
Cluster
CLUSTER ADDSLOTS slot [slot …] O(N) where N is the total number of hash slot arguments Assign new hash slots to receiving node CLUSTER BUMPEPOCH O(1) Advance the cluster config epoch CLUSTER COUNT-FAILURE-REPORTS node-id O(N) where N is the number of failure reports Return the number of failure reports active for a given node CLUSTER COUNTKEYSINSLOT slot O(1) Return the number of local keys in the specified hash slot CLUSTER DELSLOTS slot [slot …] O(N) where N is the total number of hash slot arguments Set hash slots as unbound in receiving node CLUSTER FAILOVER [FORCE/TAKEOVER] O(1) Forces a replica to perform a manual failover of its master CLUSTER FLUSHSLOTS O(1) Delete a node’s own slots information CLUSTER FORGET node-id O(1) Remove a node from the nodes table CLUSTER GETKEYSINSLOT slot count O(log(N)) where N is the number of requested keys Return local key names in the specified hash slot CLUSTER INFO O(1) Provides info about Redis Cluster node state CLUSTER KEYSLOT key O(N) where N is the number of bytes in the key Returns the hash slot of the specified key CLUSTER MEET ip port O(1) Force a node cluster to handshake with another node CLUSTER MYID O(1) Return the node id CLUSTER NODES O(N) where N is the total number of Cluster nodes Get Cluster config for the node CLUSTER REPLICATE node-id O(1) Reconfigure a node as a replica of the specified master node CLUSTER RESET [HARD|SOFT] O(N) where N is the number of known nodes. The command may execute a FLUSHALL as a side effect Reset a Redis Cluster node CLUSTER SAVECONFIG O(1) Forces the node to save cluster state on disk CLUSTER SET-CONFIG-EPOCH config-epoch O(1) Set the configuration epoch in a new node CLUSTER SETSLOT slot IMPORTING|MIGRATING|STABLE|NODE [node-id] O(1) Bind a hash slot to a specific node CLUSTER SLAVES node-id O(1) List replica nodes of the specified master node CLUSTER REPLICAS node-id O(1) List replica nodes of the specified master node CLUSTER SLOTS O(N) where N is the total number of Cluster nodes Get array of Cluster slot to node mappings READONLY O(1) Enables read queries for a connection to a cluster replica node READWRITE O(1) Disables read queries for a connection to a cluster replica node -
Connection
AUTH [username] password - Authenticate to the server CLIENT CACHING YES|NO O(1) Instruct the server about tracking or not keys in the next request CLIENT ID O(1) Returns the client ID for the current connection CLIENT INFO O(1) Returns information about the current client connection CLIENT KILL [ip:port] [ID client-id] [TYPE normal|master|slave|pubsub] [USER username] [ADDR ip:port] [SKIPME yes|no] O(N) where N is the number of client connections Kill the connection of a client CLIENT LIST [TYPE normal|master|replica|pubsub] [ID client-id [client-id …]] O(N) where N is the number of client connections Get the list of client connections CLIENT GETNAME O(1) Get the current connection name CLIENT GETREDIR O(1) Get tracking notifications redirection client ID if any CLIENT UNPAUSE O(N) Where N is the number of paused clients Resume processing of clients that were paused CLIENT PAUSE timeout [WRITE|ALL] O(1) Stop processing commands from clients for some time CLIENT REPLY ON|OFF|SKIP O(1) Instruct the server whether to reply to commands CLIENT SETNAME connection-name O(1) Set the current connection name CLIENT TRACKING ON|OFF [REDIRECT client-id] [PREFIX prefix [PREFIX prefix …]] [BCAST] [OPTIN] [OPTOUT] [NOLOOP] O(1) Enable or disable server assisted client side caching support CLIENT TRACKINGINFO O(1) Return information about server assisted client side caching for the current connection CLIENT UNBLOCK client-id [TIMEOUT|ERROR] O(log N) where N is the number of client connections Unblock a client blocked in a blocking command from a different connection ECHO message - Echo the given string HELLO [protover [AUTH username password] [SETNAME clientname]] O(1) Handshake with Redis PING [message] - Ping the server QUIT - Close the connection RESET - Reset the connection SELECT index - Change the selected database for the current connection -
Geo
GEOADD key [NX|XX] [CH] longitude latitude member [longitude latitude member …] O(log(N)) for each item added, where N is the number of elements in the sorted set Add one or more geospatial items in the geospatial index represented using a sorted set GEOHASH key member [member …] O(log(N)) for each member requested, where N is the number of elements in the sorted set Returns members of a geospatial index as standard geohash strings GEOPOS key member [member …] O(log(N)) for each member requested, where N is the number of elements in the sorted set Returns longitude and latitude of members of a geospatial index GEODIST key member1 member2 [m|km|ft|mi] O(log(N)) Returns the distance between two members of a geospatial index GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count [ANY]] [ASC|DESC] [STORE key] [STOREDIST key] 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 Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point GEORADIUSBYMEMBER key member radius m/|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count [ANY]] [ASC|DESC] [STORE key] [STOREDIST key] 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 Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member [GEOSEARCH key [FROMMEMBER member] [FROMLONLAT longitude latitude] [BYRADIUS radius m|km/ ft|mi] [BYBOX width height m|km|ft|mi] [ASC|DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH]](https://redis.io/commands/geosearch) O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape Query a sorted set representing a geospatial index to fetch members inside an area of a box or a circle GEOSEARCHSTORE destination source [FROMMEMBER member] [FROMLONLAT longitude latitude] [BYRADIUS radius m|km|ft|mi] [BYBOX width height m|km|ft|mi] [ASC|DESC] [COUNT count [ANY]] [WITHCOORD] [WITHDIST] [WITHHASH] [STOREDIST] O(N+log(M)) where N is the number of elements in the grid-aligned bounding box area around the shape provided as the filter and M is the number of items inside the shape Query a sorted set representing a geospatial index to fetch members inside an area of a box or a circle, and store the result in another key -
Hashes
HDEL key field [field …] O(N) where N is the number of fields to be removed Delete one or more hash fields HEXISTS key field O(1) Determine if a hash field exists HGET key field O(1) Get the value of a hash field HGETALL key O(N) where N is the size of the hash Get all the fields and values in a hash HINCRBY key field increment O(1) Increment the integer value of a hash field by the given number HINCRBYFLOAT key field increment O(1) Increment the float value of a hash field by the given amount HKEYS key O(N) where N is the size of the hash Get all the fields in a hash HLEN key O(1) Get the number of fields in a hash HMGET key field [field …] O(N) where N is the number of fields being requested Get the values of all the given hash fields HMSET key field value [field value …] O(N) where N is the number of fields being set Set multiple hash fields to multiple values HSET key field value [field value …] O(1) for each field/value pair added, so O(N) to add N field/value pairs when the command is called with multiple field/value pairs Set the string value of a hash field HSETNX key field value O(1) Set the value of a hash field, only if the field does not exist HSTRLEN key field O(1) Get the length of the value of a hash field HVALS key O(N) where N is the size of the hash Get all the values in a hash HSCAN key cursor [MATCH pattern] [COUNT count] 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 Incrementally iterate hash fields and associated values -
HyperLogLog
PFADD key element [element …] O(1) to add every element Adds the specified elements to the specified HyperLogLog PFCOUNT key [key …] O(1) with a very small average constant time 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 Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s) PFMERGE destkey sourcekey [sourcekey …] O(N) to merge N HyperLogLogs, but with high constant times Merge N different HyperLogLogs into a single one -
Keys
COPY source destination [DB destination-db] [REPLACE] O(N) worst case for collections, where N is the number of nested items. O(1) for string values Copy a key DEL key [key …] 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) Delete a key DUMP key O(1) to access the key and additional O(NM) to serialize 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(M) where M is small, so simply O(1) Return a serialized version of the value stored at the specified key EXISTS key [key …] O(1) Determine if a key exists EXPIRE key seconds O(1) Set a key’s time to live in seconds EXPIREAT key timestamp O(1) Set the expiration for a key as a UNIX timestamp KEYS pattern 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 Find all keys matching the given pattern MIGRATE host port key|”” destination-db timeout [COPY] [REPLACE] [AUTH password] [AUTH2 username password] [KEYS key [key …]] 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 Atomically transfer a key from a Redis instance to another one MOVE key db O(1) Move a key to another database OBJECT subcommand [arguments [arguments …]] O(1) for all the currently implemented subcommands Inspect the internals of Redis objects PERSIST key O(1) Remove the expiration from a key PEXPIRE key milliseconds O(1) Set a key’s time to live in milliseconds PEXPIREAT key milliseconds-timestamp O(1) Set the expiration for a key as a UNIX timestamp specified in milliseconds PTTL key O(1) Get the time to live for a key in milliseconds RANDOMKEY O(1) Return a random key from the keyspace RENAME key newkey O(1) Rename a key RENAMENX key newkey O(1) Rename a key, only if the new key does not exist RESTORE key ttl serialized-value [REPLACE] [ABSTTL] [IDLETIME seconds] [FREQ frequency] 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(M) 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)) Create a key using the provided serialized value, previously obtained using DUMP SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern …]] [ASC|DESC] [ALPHA] [STORE destination] O(N+Mlog(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 Sort the elements in a list, set or sorted set TOUCH key [key …] O(N) where N is the number of keys that will be touched Alters the last access time of a key(s). Returns the number of existing keys specified TTL key O(1) Get the time to live for a key TYPE key O(1) Determine the type stored at key UNLINK key [key …] O(1) for each key removed regardless of its size. Then the command does O(N) work in a different thread in order to reclaim memory, where N is the number of allocations the deleted objects where composed of Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking WAIT numreplicas timeout O(1) Wait for the synchronous replication of all the write commands sent in the context of the current connection SCAN cursor [MATCH pattern] [COUNT count] [TYPE type] 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 Incrementally iterate the keys space -
Lists
BLPOP key [key …] timeout O(1) Remove and get the first element in a list, or block until one is available BRPOP key [key …] timeout O(1) Remove and get the last element in a list, or block until one is available BRPOPLPUSH source destination timeout O(1) Pop an element from a list, push it to another list and return it; or block until one is available BLMOVE source destination LEFT|RIGHT LEFT|RIGHT timeout O(1) Pop an element from a list, push it to another list and return it; or block until one is available LINDEX key index 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) Get an element from a list by its index LINSERT key BEFORE|AFTER pivot element 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) Insert an element before or after another element in a list LLEN key O(1) Get the length of a list LPOP key [count] O(N) where N is the number of elements returned Remove and get the first elements in a list LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len] O(N) where N is the number of elements in the list, for the average case. When searching for elements near the head or the tail of the list, or when the MAXLEN option is provided, the command may run in constant time Return the index of matching elements on a list LPUSH key element [element …] O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments Prepend one or multiple elements to a list LPUSHX key element [element …] O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments Prepend an element to a list, only if the list exists LRANGE key start stop 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 Get a range of elements from a list LREM key count element O(N+M) where N is the length of the list and M is the number of elements removed Remove elements from a list LSET key index element O(N) where N is the length of the list. Setting either the first or the last element of the list is O(1) Set the value of an element in a list by its index LTRIM key start stop O(N) where N is the number of elements to be removed by the operation Trim a list to the specified range RPOP key [count] O(N) where N is the number of elements returned Remove and get the last elements in a list RPOPLPUSH source destination O(1) Remove the last element in a list, prepend it to another list and return it LMOVE source destination LEFT|RIGHT LEFT|RIGHT O(1) Pop an element from a list, push it to another list and return it RPUSH key element [element …] O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments Append one or multiple elements to a list RPUSHX key element [element …] O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments Append an element to a list, only if the list exists -
Pub/Sub
PSUBSCRIBE pattern [pattern …] O(N) where N is the number of patterns the client is already subscribed to Listen for messages published to channels matching the given patterns PUBSUB subcommand [argument [argument …]] 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 Inspect the state of the Pub/Sub subsystem PUBLISH channel message 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) Post a message to a channel PUNSUBSCRIBE [pattern [pattern …]] 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) Stop listening for messages posted to channels matching the given patterns SUBSCRIBE channel [channel …] O(N) where N is the number of channels to subscribe to Listen for messages published to the given channels UNSUBSCRIBE [channel [channel …]] O(N) where N is the number of clients already subscribed to a channel Stop listening for messages posted to the given channels -
Scripting
EVAL script numkeys key [key …] arg [arg …] Depends on the script executed Execute a Lua script server side EVALSHA sha1 numkeys key [key …] arg [arg …] Depends on the script executed Execute a Lua script server side SCRIPT DEBUG YES|SYNC|NO O(1) Set the debug mode for executed scripts SCRIPT EXISTS sha1 [sha1 …] O(N) - N number of scripts to check Check existence of scripts in the script cache SCRIPT FLUSH O(N) with N being the number of scripts in cache Remove all the scripts from the script cache SCRIPT KILL O(1) Kill the script currently in execution SCRIPT LOAD script O(N) with N being the length in bytes of the script body Load the specified Lua script into the script cache -
Server
ACL LOAD O(N). Where N is the number of configured users Reload the ACLs from the configured ACL file ACL SAVE O(N). Where N is the number of configured users Save the current ACL rules in the configured ACL file ACL LIST O(N). Where N is the number of configured users List the current ACL rules in ACL config file format ACL USERS O(N). Where N is the number of configured users List the username of all the configured ACL rules ACL GETUSER username O(N). Where N is the number of password, command and pattern rules that the user has Get the rules for a specific ACL user ACL SETUSER username [rule [rule …]] O(N). Where N is the number of rules provided Modify or create the rules for a specific ACL user ACL DELUSER username [username …] O(1) amortized time considering the typical user Remove the specified ACL users and the associated rules ACL CAT [categoryname] O(1) since the categories and commands are a fixed set List the ACL categories or the commands inside a category ACL GENPASS [bits] O(1) Generate a pseudorandom secure password to use for ACL users ACL WHOAMI O(1) Return the name of the user associated to the current connection ACL LOG [count or RESET] O(N) with N being the number of entries shown List latest events denied because of ACLs in place ACL HELP O(1) Show helpful text about the different subcommands BGREWRITEAOF - Asynchronously rewrite the append-only file BGSAVE [SCHEDULE] - Asynchronously save the dataset to disk COMMAND O(N) where N is the total number of Redis commands Get array of Redis command details COMMAND COUNT O(1) Get total number of Redis commands COMMAND GETKEYS O(N) where N is the number of arguments to the command Extract keys given a full Redis command COMMAND INFO command-name [command-name …] O(N) when N is number of commands to look up Get array of specific Redis command details CONFIG GET parameter - Get the value of a configuration parameter CONFIG REWRITE - Rewrite the configuration file with the in memory configuration CONFIG SET parameter value - Set a configuration parameter to the given value CONFIG RESETSTAT O(1) Reset the stats returned by INFO DBSIZE - Return the number of keys in the selected database DEBUG OBJECT key - Get debugging information about a key DEBUG SEGFAULT - Make the server crash FLUSHALL [ASYNC] - Remove all keys from all databases FLUSHDB [ASYNC] - Remove all keys from the current database INFO [section] - Get information and statistics about the server LOLWUT [VERSION version] - Display some computer art and the Redis version LASTSAVE - Get the UNIX time stamp of the last successful save to disk MEMORY DOCTOR - Outputs memory problems report MEMORY HELP - Show helpful text about the different subcommands MEMORY MALLOC-STATS - Show allocator internal stats MEMORY PURGE - Ask the allocator to release memory MEMORY STATS - Show memory usage details MEMORY USAGE key [SAMPLES count] O(N) where N is the number of samples Estimate the memory usage of a key MODULE LIST O(N) where N is the number of loaded modules List all modules loaded by the server MODULE LOAD path [ arg [arg …]] O(1) Load a module MODULE UNLOAD name O(1) Unload a module MONITOR - Listen for all requests received by the server in real time ROLE - Return the role of the instance in the context of replication SAVE - Synchronously save the dataset to disk SHUTDOWN [NOSAVE/SAVE] - Synchronously save the dataset to disk and then shut down the server SLAVEOF host port - Make the server a replica of another instance, or promote it as master. Deprecated starting with Redis 5. Use REPLICAOF instead REPLICAOF host port - Make the server a replica of another instance, or promote it as master SLOWLOG subcommand [argument] - Manages the Redis slow queries log SWAPDB index1 index2 O(N) where N is the count of clients watching or blocking on keys from both databases Swaps two Redis databases SYNC - Internal command used for replication PSYNC replicationid offset - Internal command used for replication TIME O(1) Return the current server time LATENCY DOCTOR - Return a human readable latency analysis report LATENCY GRAPH event - Return a latency graph for the event LATENCY HISTORY event - Return timestamp-latency samples for the event LATENCY LATEST - Return the latest latency samples for all events LATENCY RESET [event [event …]] - Reset latency data for one or more events LATENCY HELP - Show helpful text about the different subcommands -
Sets
SADD key member [member …] O(1) for each element added, so O(N) to add N elements when the command is called with multiple arguments Add one or more members to a set SCARD key O(1) Get the number of members in a set SDIFF key [key …] O(N) where N is the total number of elements in all given sets Subtract multiple sets SDIFFSTORE destination key [key …] O(N) where N is the total number of elements in all given sets Subtract multiple sets and store the resulting set in a key SINTER key [key …] O(NM) worst case where N is the cardinality of the smallest set and M is the number of sets Intersect multiple sets SINTERSTORE destination key [key …] O(NM) worst case where N is the cardinality of the smallest set and M is the number of sets Intersect multiple sets and store the resulting set in a key SISMEMBER key member O(1) Determine if a given value is a member of a set SMISMEMBER key member [member …] O(N) where N is the number of elements being checked for membership Returns the membership associated with the given elements for a set SMEMBERS key O(N) where N is the set cardinality Get all the members in a set SMOVE source destination member O(1) Move a member from one set to another SPOP key [count] O(1) Remove and return one or multiple random members from a set SRANDMEMBER key [count] Without the count argument O(1), otherwise O(N) where N is the absolute value of the passed count Get one or multiple random members from a set SREM key member [member …] O(N) where N is the number of members to be removed Remove one or more members from a set SUNION key [key …] O(N) where N is the total number of elements in all given sets Add multiple sets SUNIONSTORE destination key [key …] O(N) where N is the total number of elements in all given sets Add multiple sets and store the resulting set in a key SSCAN key cursor [MATCH pattern] [COUNT count] 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 Incrementally iterate Set elements -
Sorted Sets
BZPOPMIN key [key …] timeout O(log(N)) with N being the number of elements in the sorted set Remove and return the member with the lowest score from one or more sorted sets, or block until one is available BZPOPMAX key [key …] timeout O(log(N)) with N being the number of elements in the sorted set Remove and return the member with the highest score from one or more sorted sets, or block until one is available ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member …] O(log(N)) for each item added, where N is the number of elements in the sorted set Add one or more members to a sorted set, or update its score if it already exists ZCARD key O(1) Get the number of members in a sorted set ZCOUNT key min max O(log(N)) with N being the number of elements in the sorted set Count the members in a sorted set with scores within the given values ZDIFF numkeys key [key …] [WITHSCORES] O(L + (N-K)log(N)) worst case where L is the total number of elements in all the sets, N is the size of the first set, and K is the size of the result set Subtract multiple sorted sets ZDIFFSTORE destination numkeys key [key …] O(L + (N-K)log(N)) worst case where L is the total number of elements in all the sets, N is the size of the first set, and K is the size of the result set Subtract multiple sorted sets and store the resulting sorted set in a new key ZINCRBY key increment member O(log(N)) where N is the number of elements in the sorted set Increment the score of a member in a sorted set ZINTER numkeys key [key …] [WEIGHTS weight [weight …]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES] 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 Intersect multiple sorted sets ZINTERSTORE destination numkeys key [key …] [WEIGHTS weight [weight …]] [AGGREGATE SUM|MIN|MAX] *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 Intersect multiple sorted sets and store the resulting sorted set in a new key ZLEXCOUNT key min max O(log(N)) with N being the number of elements in the sorted set Count the number of members in a sorted set between a given lexicographical range ZPOPMAX key [count] O(Mlog(N)) with N being the number of elements in the sorted set, and M being the number of elements popped Remove and return members with the highest scores in a sorted set ZPOPMIN key [count] O(Mlog(N)) with N being the number of elements in the sorted set, and M being the number of elements popped Remove and return members with the lowest scores in a sorted set ZRANGESTORE dst src min max [BYSCORE/BYLEX] [REV] [LIMIT offset count] O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements stored into the destination key Store a range of members from sorted set into another key ZRANGE key min max [BYSCORE|BYLEX] [REV] [LIMIT offset count] [WITHSCORES] O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned Return a range of members in a sorted set ZRANGEBYLEX key min max [LIMIT offset count] 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)) Return a range of members in a sorted set, by lexicographical range ZREVRANGEBYLEX key max min [LIMIT offset count] 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)) Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count] 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)) Return a range of members in a sorted set, by score ZRANK key member O(log(N)) Determine the index of a member in a sorted set ZREM key member [member …] O(Mlog(N)) with N being the number of elements in the sorted set and M the number of elements to be removed Remove one or more members from a sorted set ZREMRANGEBYLEX key min max 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 Remove all members in a sorted set between the given lexicographical range ZREMRANGEBYRANK key start stop 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 Remove all members in a sorted set within the given indexes ZREMRANGEBYSCORE key min max 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. Remove all members in a sorted set within the given scores ZREVRANGE key start stop [WITHSCORES] O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned Return a range of members in a sorted set, by index, with scores ordered from high to low ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count] 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)) Return a range of members in a sorted set, by score, with scores ordered from high to low ZREVRANK key member O(log(N)) Determine the index of a member in a sorted set, with scores ordered from high to low ZSCORE key member O(1) Get the score associated with the given member in a sorted set ZUNION numkeys key [key …] [WEIGHTS weight [weight …]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES] *O(N)+O(Mlog(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 Add multiple sorted sets ZMSCORE key member [member …] O(N) where N is the number of members being requested Get the score associated with the given members in a sorted set ZUNIONSTORE destination numkeys key [key …] [WEIGHTS weight [weight …]] [AGGREGATE SUM|MIN|MAX] 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 Add multiple sorted sets and store the resulting sorted set in a new key ZSCAN key cursor [MATCH pattern] [COUNT count] 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 Incrementally iterate sorted sets elements and associated scores -
Streams
XINFO [CONSUMERS key groupname] [GROUPS key] [STREAM key] [HELP] O(N) with N being the number of returned items for the subcommands CONSUMERS and GROUPS. The STREAM subcommand is O(log N) with N being the number of items in the stream Get information on streams and consumer groups XADD key [NOMKSTREAM] [MAXLEN|MINID [=|~] threshold [LIMIT count]] *|ID field value [field value …] O(1) when adding a new entry, O(N) when trimming where N being the number of entires evicted Appends a new entry to a stream XTRIM key MAXLEN|MINID [=|~] threshold [LIMIT count] O(N), with N being the number of evicted entries Trims the stream to (approximately if ‘~’ is passed) a certain size XDEL key ID [ID …] O(1) for each single item to delete in the stream, regardless of the stream size Removes the specified entries from the stream. Returns the number of items actually deleted, that may be different from the number of IDs passed in case certain IDs do not exist XRANGE key start end [COUNT count] O(N) with N being the number of elements being returned Return a range of elements in a stream, with IDs matching the specified IDs interval XREVRANGE key end start [COUNT count] O(N) with N being the number of elements being returned Return a range of elements in a stream, with IDs matching the specified IDs interval, in reverse order (from greater to smaller IDs compared to XRANGE XLEN key O(1) Return the number of entries in a stream XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key …] ID [ID …] For each stream mentioned: O(N) with N being the number of elements being returned, it means that XREAD-ing with a fixed COUNT is O(1). Note that when the BLOCK option is used, XADD will pay O(M) time in order to serve the M clients blocked on the stream getting new data Return never seen elements in multiple streams, with IDs greater than the ones reported by the caller for each stream. Can block XGROUP [CREATE key groupname ID|$ [MKSTREAM]] [SETID key groupname ID|$] [DESTROY key groupname] [CREATECONSUMER key groupname consumername] [DELCONSUMER key groupname consumername] O(1) for all the subcommands, with the exception of the DESTROY subcommand which takes an additional O(M) time in order to delete the M entries inside the consumer group pending entries list (PEL) Create, destroy, and manage consumer groups XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS key [key …] ID [ID …] For each stream mentioned: O(M) with M being the number of elements returned. If M is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1). On the other side when XREADGROUP blocks, XADD will pay the O(N) time in order to serve the N clients blocked on the stream getting new data Return new entries from a stream using a consumer group, or access the history of the pending entries for a given consumer. Can block XACK key group ID [ID …] O(1) Marks a pending message as correctly processed, effectively removing it from the pending entries list of the consumer group. Return value of the command is the number of messages successfully acknowledged, that is, the IDs we were actually able to resolve in the PEL XCLAIM key group consumer min-idle-time ID [ID …] [IDLE ms] [TIME ms-unix-time] [RETRYCOUNT count] [FORCE] [JUSTID] O(log N) Changes (or acquires) ownership of a message in a consumer group, as if the message was delivered to the specified consumer XAUTOCLAIM key group consumer min-idle-time start [COUNT count] [JUSTID] O(1) if COUNT is small Changes (or acquires) ownership of messages in a consumer group, as if the messages were delivered to the specified consumer XPENDING key group [[IDLE min-idle-time] start end count [consumer]] O(N) with N being the number of elements returned, so asking for a small fixed number of entries per call is O(1). O(M), where M is the total number of entries scanned when used with the IDLE filter. When the command returns just the summary and the list of consumers is small, it runs in O(1) time; otherwise, an additional O(N) time for iterating every consumer Return information and entries from a stream consumer group pending entries list, that are messages fetched but never acknowledged -
Strings
APPEND key value O(1) Append a value to a key BITCOUNT key [start end] O(N) Count set bits in a string BITFIELD key [GET type offset] [SET type offset value] [INCRBY type offset increment] [OVERFLOW WRAP|SAT|FAIL] O(1) Perform arbitrary bitfield integer operations on strings. Multiple operations, returns array BITOP operation destkey key [key …] O(N) Perform bitwise operations between strings BITPOS key bit [start] [end] O(N) Find first bit set or clear in a string, start and end are interpreted as range of bytes DECR key O(1) Decrement the integer value of a key by one. Limited to 64 bit signed integers DECRBY key decrement O(1) Decrement the integer value of a key by the given number GET key O(1) Get the value of a key GETBIT key offset O(1) Returns the bit value at offset in the string value stored at key GETRANGE key start end O(N); O(1) for small strings Get a substring of the string stored at a key GETSET key value O(1) Set the string value of a key and return its old value INCR key O(1) Increment the integer value of a key by one INCRBY key increment O(1) Increment the integer value of a key by the given amount INCRBYFLOAT key increment O(1) Increment the float value of a key by the given amount MGET key [key …] O(N) where N is the no. of keys to retrieve Get the values of all the given keys MSET key value [key value …] O(N) where N is the no. of keys to set Set multiple keys to multiple values. It is atomic MSETNX key value [key value …] O(N) where N is the no. of keys to set Set multiple keys to multiple values, only if none of the keys exist PSETEX key milliseconds value O(1) Set the value and expiration in milliseconds of a key SET key value [EX seconds|PX milliseconds|KEEPTTL] [NX|XX] [GET] O(1) Set the string value of a key SETBIT key offset value O(1) Sets or clears the bit at offset in the string value stored at key SETEX key seconds value O(1) Set the value and expiration of a key SETNX key value O(1) Set the value of a key, only if the key does not exist SETRANGE key offset O(1) Overwrite part of a string at key starting at the specified offset STRALGO LCS algo-specific-argument [algo-specific-argument …] O(strlen(s1).strlen(s2)) Run algorithms (currently LCS) against strings. STRALGO LCS [KEYS ...] [STRINGS ...] [LEN] [IDX] [MINMATCHLEN <len>] [WITHMATCHLEN]
STRLEN key O(1) Get the length of the value stored in a key -
Transactions
DISCARD Discard all commands issued after MULTI EXEC Execute all commands issued after MULTI MULTI Mark the start of a transaction block UNWATCH Forget about all watched keys WATCH key [key …] Watch the given keys to determine execution of theMULTI/EXEC block