For developersRedis Commands Cheat sheet
Connect
CLI
RedisInsight
Download RedisInsight to visually explore your Redis data or to engage with raw Redis commands in the workbench.

node-redis
redis-py
NRedisStack
Jedis
NOTE
To setup Redis either locally or in the cloud, refer to the tutorial
Strings/Numbers
CLI
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| SET | SET key value | SET myKey "Hello" | "OK" | Set key to hold the string value. If key already holds a value, it is overwritten, regardless of its type. Time Complexity: O(1) |
| GET | GET key | GET myKey | "Hello" | Get the string value of key. If the key does not exist the special value nil is returned. Time Complexity: O(1) |
| MGET | MGET key [key ...] | MGET myKey nonExistentKey | 1) "Hello" 2) (nil) | 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) |
| INCR | INCR key | INCR myCounter | (integer) 1 | 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
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| KEYS | KEYS pattern | KEYS my* | 1) "myKey" 2) "myCounter" | Returns all keys matching pattern. Time Complexity: O(N) |
| EXISTS | EXISTS key [key ...] | EXISTS myKey | (integer) 1 | Checks if one or more keys exist. Time Complexity: O(N) |
| EXPIRE | EXPIRE key seconds | EXPIRE myKey 120 | (integer) 1 | Set a timeout on a key. After the timeout has expired, the key will automatically be deleted. Time Complexity: O(1) |
| TTL | TTL key | TTL myKey | (integer) 113 | Returns the remaining time to live of a key that has a timeout. Time Complexity: O(1) |
| PERSIST | PERSIST key | PERSIST myKey | (integer) 1 | Removes the expiration from a key. Time Complexity: O(1) |
| SCAN | SCAN cursor [MATCH pattern] [COUNT count] | SCAN 0 MATCH my* COUNT 2 | 1) "3" 2) 1) "myCounter" 2) "myKey" | Iterates the set of keys in the currently selected Redis database. Time Complexity: O(1) for every call. O(N) for a complete iteration. |
| DEL | DEL key [key ...] | DEL myKey | (integer) 1 | Removes the specified keys. Time Complexity: O(N) |
| INFO | INFO [section] | INFO keyspace | # Keyspace db0:keys=2,expires=0,avg_ttl=0 | 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
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| HSET | HSET key field value [field value ...] | HSET h_employee_profile:101 name "Nicol" age 33 | (integer) 2 | Sets the specified fields to their respective values in the hash stored at key. Time Complexity: O(N) |
| HGET | HGET key field | HGET h_employee_profile:101 name | "Nicol" | Returns the value associated with field in the hash stored at key. Time Complexity: O(1) |
| HGETALL | HGETALL key | HGETALL h_employee_profile:101 | 1) "name" 2) "Nicol" 3) "age" 4) "33" | Returns all fields and values of the hash stored at key. Time Complexity: O(N) |
| HMGET | HMGET key field1 [field2] | HMGET h_employee_profile:101 name age | 1) "Nicol" 2) "33" | 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
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| SADD | SADD key member [member ...] | SADD mySet "Hello" | (integer) 1 | Adds the specified members to the set stored at key. Time Complexity: O(N) |
| SMEMBERS | SMEMBERS key | SMEMBERS mySet | 1) "Hello" | Returns all the members of the set value stored at key. Time Complexity: O(N) |
| SCARD | SCARD key | SCARD mySet | (integer) 1 | Returns the set cardinality (number of elements) of the set stored at key. Time Complexity: O(1) |
| SISMEMBER | SISMEMBER key member | SISMEMBER mySet "Hello" | (integer) 1 | Returns if member is a member of the set stored at key. Time Complexity: O(1) |
| SDIFF | SDIFF key1 [key2] | SDIFF mySet myOtherSet | 1) "Hello" | Returns the members of the set resulting from the difference between the first set and all the successive sets. Time Complexity: O(N) |
| SDIFFSTORE | SDIFFSTORE destination key1 [key2] | SDIFFSTORE myNewSet mySet myOtherSet | (integer) 1 | This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination. Time Complexity: O(N) |
| SREM | SREM key member [member ...] | SREM mySet "Hello" | (integer) 1 | Removes the specified members from the set stored at key. |
node-redis
redis-py
NRedisStack
Jedis
Sorted sets
CLI
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| ZADD | ZADD key score member [score member ...] | ZADD myZSet 1 "one" 2 "two" | (integer) 2 | Adds all the specified members with the specified scores to the sorted set stored at key. Time Complexity: O(log(N)) |
| ZRANGE | ZRANGE key start stop [WITHSCORES] | ZRANGE myZSet 0 -1 | 1) "one" 2) "two" | 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
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| LPUSH | LPUSH key value [value ...] | LPUSH myList "World" | (integer) 1 | Inserts the specified values at the head of the list stored at key. Time Complexity: O(N) |
| RPUSH | RPUSH key value [value ...] | RPUSH myList "Hello" | (integer) 2 | Inserts the specified values at the tail of the list stored at key. Time Complexity: O(N) |
| LRANGE | LRANGE key start stop | LRANGE myList 0 -1 | 1) "World" 2) "Hello" | 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. |
| LLEN | LLEN key | LLEN myList | (integer) 2 | Returns the length of the list stored at key. Time Complexity: O(1) |
| LPOP | LPOP key [count] | LPOP myList | "World" | Removes and returns the first element of the list stored at key. Time Complexity: O(N) |
| RPOP | RPOP key [count] | RPOP myList | "Hello" | Removes and returns the last element of the list stored at key. Time Complexity: O(N) |
node-redis
redis-py
NRedisStack
Jedis
Streams
CLI
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| XADD | XADD key field value [field value ...] | XADD myStream * sensorId "1234" temperature "19.8" | 1518951480106-0 | Appends the specified stream entry to the stream at the specified key. Time Complexity: O(1) when adding a new entry. |
| XREAD | XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...] ID [ID ...] | XREAD COUNT 2 STREAMS myStream 0 | 1) 1) "myStream" 2) 1) 1) "1518951480106-0" 2) 1) "sensorId" 2) "1234" 3) "temperature" 4) "19.8" | Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller. |
| XRANGE | XRANGE key start end [COUNT count] | XRANGE myStream 1518951480106-0 1518951480106-0 | 1) 1) "1518951480106-0" 2) 1) "sensorId" 2) "1234" 3) "temperature" 4) "19.8" | 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). |
| XLEN | XLEN key | XLEN myStream | (integer) 1 | Returns the number of entries of a stream. Time Complexity: O(1) |
| XDEL | XDEL key ID [ID ...] | XDEL myStream 1518951480106-0 | (integer) 1 | Removes the specified entries from a stream. Time Complexity: O(1) for each single item to delete in the stream |
| XTRIM | XTRIM key MAXLEN [~] count | XTRIM myStream MAXLEN 0 | (integer) 0 | 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
JSON
CLI
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| JSON.SET | JSON.SET key path value | JSON.SET employee_profile:1 . '{"name":"Alice"}' | OK | 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.GET | JSON.GET key [path [path ...]] | JSON.GET employee_profile:1 | {"name":"Alice"} | 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.NUMINCRBY | JSON.NUMINCRBY key path number | JSON.NUMINCRBY employee_profile:1 .age 5 | 35 | 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.OBJKEYS | JSON.OBJKEYS key [path] | JSON.OBJKEYS employee_profile:1 | 1) "name" 2) "age" | 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.OBJLEN | JSON.OBJLEN key [path] | JSON.OBJLEN employee_profile:1 | (integer) 2 | 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.ARRAPPEND | JSON.ARRAPPEND key [path] value [value ...] | JSON.ARRAPPEND employee_profile:1 .colors '"yellow"' | (integer) 4 | 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.ARRINSERT | JSON.ARRINSERT key path index value [value ...] | JSON.ARRINSERT employee_profile:1 .colors 2 '"purple"' | (integer) 5 | 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.ARRINDEX | JSON.ARRINDEX key path value [start [stop]] | JSON.ARRINDEX employee_profile:1 .colors '"purple"' | (integer) 2 | 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
| Command | Syntax | Example | Output | Description |
|---|---|---|---|---|
| FT.CREATE | FT.CREATE index [ON HASH / JSON] [PREFIX count prefix [prefix ...]] SCHEMA field_name [AS alias] TEXT / TAG / NUMERIC / GEO ... | FT.CREATE staff:index ON JSON PREFIX 1 staff: SCHEMA "$.name" AS name TEXT "$.age" AS age NUMERIC | OK | 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.SEARCH | FT.SEARCH index query [RETURN count identifier ...] [SORTBY sortby] [LIMIT offset num] | FT.SEARCH staff:index "(@name:'alex')" RETURN 1 $ LIMIT 0 10 | Matching documents data | Search the index with a query, returning either documents or just ids. Time Complexity: O(N) |
| FT.AGGREGATE | FT.AGGREGATE index query [GROUPBY nargs property ...] [REDUCE function nargs arg ...] [SORTBY nargs ...] | FT.AGGREGATE staff:index "(@age:[(18 +inf])" GROUPBY 1 @age REDUCE COUNT_DISTINCT 1 @name AS staff_count | Aggregated results by age | Run a search query on an index, and perform aggregate transformations on the results. |
| FT.INFO | FT.INFO index | FT.INFO staff:index | Index configuration and stats | Return information and statistics on the index. Time Complexity: O(1) |
| FT.DROPINDEX | FT.DROPINDEX index [DD] | FT.DROPINDEX staff:index | OK | Dropping existing index. Time Complexity: O(1) or O(N) if documents are deleted, where N is the number of keys in the keyspace |

