Turn your slow data into fast data--and keep it in sync with Redis Cloud

Join the RDI Public Preview
For developersRedis Commands Cheat sheet
Prasan Kumar
Prasan Kumar
Will Johnston
Will Johnston

Connect

CLI

RedisInsight

Download RedisInsight to visually explore your Redis data or to engage with raw Redis commands in the workbench.

Image

node-redis

redis-py

NRedisStack

Jedis

NOTE

To setup Redis either locally or in the cloud, refer to the tutorial

Strings/Numbers

CLI

CommandSyntaxExampleOutput
SETSET key value"OK"
Description: Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type.Time Complexity: O(1)
GETGET key"Hello"
Description: Get the string value of key. If the key does not exist the special value nil is returned.Time Complexity: O(1)
MGETMGET key [key ...]1) "Hello" 2) (nil)
Description: Returns the values of all specified keys. For every key that does not hold a string value or does not exist, the special value nil is returned.Time Complexity: O(N)
INCRINCR key(integer) 1
Description: Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.Time Complexity: O(1)

node-redis

redis-py

NRedisStack

Jedis

Generic

CLI

CommandSyntaxExampleOutput
KEYSKEYS pattern1) "myKey" 2) "myCounter"
Description: Returns all keys matching pattern.Time Complexity: O(N)
EXISTSEXISTS key [key ...](integer) 1
Description: Checks if one or more keys exist.Time Complexity: O(N)
EXPIREEXPIRE key seconds(integer) 1
Description: Set a timeout on a key.After the timeout has expired, the key will automatically be deleted.Time Complexity:O(1)
TTLTTL key(integer) 113
Description: Returns the remaining time to live of a key that has a timeout.Time Complexity: O(1)
PERSISTPERSIST key(integer) 1
Description: Removes the expiration from a key.Time Complexity:O(1)
SCANSCAN cursor [MATCH pattern] [COUNT count]1) "3" 2) 1) "myCounter" 2) "myKey"
Description: Iterates the set of keys in the currently selected Redis database.Time Complexity: O(1) for every call. O(N) for a complete iteration.
DELDEL key [key ...](integer) 1
Description: Removes the specified keys.Time Complexity: O(N)
INFOINFO [section]# Server

redis_version:6.2.5

redis_git_sha1:00000000

redis_build_id:9893b2a-dirty

redis_mode:standalone

os:Linux 5.4.72-microsoft-standard-WSL2 x86_64

arch_bits:64

...

# Keyspace db0:keys=2,expires=0,avg_ttl=0 | | Description:Returns information and statistics about the server, with the different sections like - server, clients, memory, persistence, stats, replication, cpu, commandstats, latencystats, sentinel, cluster, modules, keyspace, errorstats.Time Complexity: O(1) |

node-redis

redis-py

NRedisStack

Jedis

Hashes

CLI

CommandSyntaxExampleOutput
HSETHSET key field value [field value ...](integer) 2
Description: Sets the specified fields to their respective values in the hash stored at key.Time Complexity: O(N)
HGETHGET key field"Nicol"
Description: Returns the value associated with field in the hash stored at key.Time Complexity: O(1)
HGETALLHGETALL key1) "name" 2) "Nicol" 3) "age" 4) "33"
Description: Returns all fields and values of the hash stored at key.Time Complexity: O(N)
HMGETHMGET key field1 [field2]1) "Nicol" 2) "33"
Description: Returns the values associated with the specified fields in the hash stored at key.Time Complexity: O(N)

node-redis

redis-py

NRedisStack

Jedis

Sets

CLI

CommandSyntaxExampleOutput
SADDSADD key member [member ...](integer) 1
Description: Adds the specified members to the set stored at key. Time Complexity: O(N)
SMEMBERSSMEMBERS key1) "Hello"
Description: Returns all the members of the set value stored at key.Time Complexity: O(N)
SCARDSCARD key(integer) 1
Description: Returns the set cardinality (number of elements) of the set stored at key.Time Complexity: O(1)
SISMEMBERSISMEMBER key member(integer) 1
Description: Returns if member is a member of the set stored at key.Time Complexity: O(1)
SDIFFSDIFF key1 [key2]1) "Hello"
Description: Returns the members of the set resulting from the difference between the first set and all the successive sets.Time Complexity: O(N)
SDIFFSTORESDIFFSTORE destination key1 [key2](integer) 1
Description: This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination.Time Complexity: O(N)
SREMSREM key member [member ...]Description: This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination.Time Complexity: O(N)(integer) 1
Description: Removes the specified members from the set stored at key.

node-redis

redis-py

NRedisStack

Jedis

Sorted sets

CLI

CommandSyntaxExampleOutput
ZADDZADD key score member [score member ...](integer) 2
Description: Adds all the specified members with the specified scores to the sorted set stored at key. Time Complexity: O(log(N))
ZRANGEZRANGE key start stop [WITHSCORES]1) "one" 2)"two"
Description: Returns the specified range of elements in the sorted set stored at key.Time Complexity: O(log(N)+M) where M is the number of elements returned

node-redis

redis-py

NRedisStack

Jedis

Lists

CLI

CommandSyntaxExampleOutput
LPUSHLPUSH key value [value ...](integer) 1
Description: Inserts the specified values at the head of the list stored at key. Time Complexity: O(N)
RPUSHRPUSH key value [value ...](integer) 2
Description: Inserts the specified values at the tail of the list stored at key.Time Complexity: O(N)
LRANGELRANGE key start stop1) "World" 2) "Hello"
Description: Returns the specified elements of the list stored at key.Time Complexity: O(S+N) where S is the distance of start and N is the number of elements in the specified range.
LLENLLEN key(integer) 2
Description: Returns the length of the list stored at key.Time Complexity: O(1)
LPOPLPOP key [count]"World"
Description: Removes and returns the first element of the list stored at key.Time Complexity: O(N)
RPOPRPOP key [count]"Hello"
Description: Removes and returns the last element of the list stored at key.Time Complexity: O(N)

node-redis

redis-py

NRedisStack

Jedis

Streams

CLI

CommandSyntaxExampleOutput
XADDXADD key field value [field value ...]1518951480106-0
Description: Appends the specified stream entry to the stream at the specified key. Time Complexity: O(1) when adding a new entry.
XREADXREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...]1) 1) "myStream" 2) 1) 1) "1518951480106-0" 2) 1) "sensorId" 2) "1234" 3) "temperature" 4) "19.8"
Description: Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller.
XRANGEXRANGE key start end [COUNT count]1) 1) 1) "1518951480106-0" 2) 1) "sensorId" 2) "1234" 3) "temperature" 4) "19.8"
Description: Returns the entries matching a range of IDs in a stream. Time Complexity: O(N) with N being the number of elements being returned. If N is constant (e.g. always asking for the first 10 elements with COUNT), you can consider it O(1).
XLENXLEN key(integer) 1
Description: Returns the number of entries of a stream. Time Complexity: O(1)
XDELXDEL key ID [ID ...](integer) 1
Description: Removes the specified entries from a stream. Time Complexity: O(1) for each single item to delete in the stream
XTRIMXTRIM key MAXLEN [~] count(integer) 0
Description: Trims the stream to a different length. Time Complexity: O(N), with N being the number of evicted entries. Constant times are very small however, since entries are organized in macro nodes containing multiple entries that can be released with a single deallocation.

node-redis

redis-py

NRedisStack

Jedis

REDIS STACK COMMANDS

Redis stack extends the core features of Redis OSS like querying across hashes and JSON documents, time series data support, full-text search ..etc

JSON

CLI

CommandSyntaxExampleOutput
JSON.SETJSON.SET key path valueOK
Description: Sets JSON value at path in key.Time Complexity: O(M+N) where M is the original size and N is the new size
JSON.GETJSON.GET key [path [path ...]]
Description: Returns the JSON value at path in key.Time Complexity: O(N) when path is evaluated to a single value where N is the size of the value, O(N) when path is evaluated to multiple values, where N is the size of the key
JSON.NUMINCRBYJSON.NUMINCRBY key path number35
Description: Increments a number inside a JSON document.Time Complexity: O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
JSON.OBJKEYSJSON.OBJKEYS key [path]1) "name" 2) "age"
Description: Return the keys in the object that's referenced by path. Time Complexity: O(N) when path is evaluated to a single value, where N is the number of keys in the object, O(N) when path is evaluated to multiple values, where N is the size of the key
JSON.OBJLENJSON.OBJLEN key [path](integer) 2
Description: Report the number of keys in the JSON object at path in key. Time Complexity: O(1) when path is evaluated to a single value, O(N) when path is evaluated to multiple values, where N is the size of the key
JSON.ARRAPPENDJSON.ARRAPPEND key [path] value [value ...](integer) 4
Description: Append the json values into the array at path after the last element in it. Time Complexity: O(1) for each value added, O(N) for multiple values added where N is the size of the key
JSON.ARRINSERTJSON.ARRINSERT key path index value [value ...](integer) 5
Description: Insert the json values into the array at path before the index (shifts to the right). Time Complexity: O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key
JSON.ARRINDEXJSON.ARRINDEX key path value [start [stop]](integer) 2
Description: Searches for the first occurrence of a JSON value in an array. Time Complexity: O(N) when path is evaluated to a single value where N is the size of the array, O(N) when path is evaluated to multiple values, where N is the size of the key

node-redis

redis-py

NRedisStack

Jedis

Search and Query

CLI

CommandSyntaxExampleOutput
FT.CREATEOK
Description: Create an index with the given specification.Time Complexity: O(K) where K is the number of fields in the document, O(N) for keys in the keySpace
FT.SEARCHMatching documents data
Description: Search the index with a query, returning either documents or just ids. Time Complexity: O(N)
FT.AGGREGATELRANGE key start stop
Description: Run a search query on an index, and perform aggregate transformations on the results.
FT.INFOFT.INFO indexA list of configuration parameters and stats for the index.
Description: Return information and statistics on the index.Time Complexity: O(1)
FT.DROPINDEXFT.DROPINDEX index [DD]OK
Description: Dropping existing index.Time Complexity:O(1) or O(N) if documents are deleted, where N is the number of keys in the keyspace

node-redis

redis-py

NRedisStack

Jedis