Learn Develop Commands cheat sheet
Redis Commands
Cheat sheet
Author
Prasan Kumar, Technical Solutions Developer
at Redis
Author
Will Johnston, Developer Growth Manager at
Redis
Connect Welcome 👋
CLI RedisInsight node-How canredis- NRedisStack
we help you today?
Jedis
redis py
Talk to sales
# Syntax
redis-cli -u redis://host:port Ask a question
redis-cli -u redis://username:password@h
Try free
# Examples Customer support
redis-cli
By using this chat box, you are agreeing to Redis'
redis-cli -u redis://localhost:6379
Privacy Policy. https://redis.io/legal/privacy-policy/
redis-cli -u redis://myuser:mypassword@l
# If you run Redis through Docker
docker exec -it <container-id-or-name> r
NOTE
To setup Redis either locally or in the cloud,
refer to the tutorial
Strings/Numbers
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax Example
SET
SET key SET myKey "Hello"
value
Description: Set key to hold the string value. If key
value, it is overwritten, regardless of its type.Time C
GET
GET GET myKey
key
Description: Get the string value of key. If the key
special value nil is returned.Time Complexity: O(1)
MGET
MGET key MGET myKey nonExisten
[key ...]
Description: Returns the values of all specified key
that does not hold a string value or does not exist
nil is returned.Time Complexity: O(N)
INCR
INCR INCR myCounter
key
Description: Increments the number stored at key
does not exist, it is set to 0 before performing the
Complexity: O(1)
Generic
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax Example
KEYS
KEYS KEYS my*
pattern
Description: Returns all keys matching pattern.Tim
EXISTS
EXISTS key [key EXISTS myKey
...]
Description: Checks if one or more keys exist.Time
EXPIRE
EXPIRE key EXPIRE myKey 120
seconds
Description: Set a timeout on a key.After the timeo
be deleted.Time Complexity:O(1)
TTL TTL key TTL myKey
Description: Returns the remaining time to live of a
Complexity: O(1)
PERSIST
PERSIST PERSIST myKey
key
Description: Removes the expiration from a key.Tim
SCAN
cursor
[MATCH
SCAN SCAN 0 MATCH my* COU
pattern]
[COUNT
count]
Description: Iterates the set of keys in the current
Complexity: O(1) for every call. O(N) for a complete
DEL key
DEL DEL myKey
[key ...]
Description: Removes the specified keys.Time Com
INFO INFO server
INFO
[section] INFO keyspace
Description:Returns information and statistics abo
like - server, clients, memory, persistence, stats, re
sentinel, cluster, modules, keyspace, errorstats.Tim
Hashes
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax
HSET
key
field
HSET HSET h_employee_prof
value
[field
value ...]
Description: Sets the specified fields to their respe
Complexity: O(N)
HGET
HGET key HGET h_employee_prof
field
Description: Returns the value associated with fiel
Complexity: O(1)
HGETALL
HGETALL HGETALL h_employee_p
key
Description: Returns all fields and values of the ha
HMGET
key
HMGET HMGET h_employee_pro
field1
[field2]
Description: Returns the values associated with th
key.Time Complexity: O(N)
Sets
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax Ex
SADD key
SADD member SADD mySet "Hell
[member ...]
Description: Adds the specified members to the se
SMEMBERS
SMEMBERS SMEMBERS mySet
key
Description: Returns all the members of the set va
SCARD SCARD key SCARD mySet
Description: Returns the set cardinality (number o
key.Time Complexity: O(1)
SISMEMBER
SISMEMBER key SISMEMBER mySet
member
Description: Returns if member is a member of the
O(1)
SDIFF key1
SDIFF SDIFF mySet myOt
[key2]
Description: Returns the members of the set result
first set and all the successive sets.Time Complexi
SDIFFSTORE
SDIFFSTORE destination SDIFFSTORE myNew
key1 [key2]
Description: This command is equal to SDIFF, but in
is stored in destination.Time Complexity: O(N)
SREM key
SREM member SREM mySet "Hell
[member ...]
Description: Removes the specified members from
Sorted sets
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax Examp
ZADD key
score
ZADD member ZADD myZSet 1 "
[score
member ...]
Description: Adds all the specified members with t
sorted set stored at key. Time Complexity: O(log(N
ZRANGE key
ZRANGE start stop ZRANGE myZSet 0
[WITHSCORES]
Description: Returns the specified range of elemen
at key.Time Complexity: O(log(N)+M) where M is th
returned
Lists
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax Example
LPUSH
key
LPUSH value LPUSH myList "World"
[value
...]
Description: Inserts the specified values at the hea
stored at key. Time Complexity: O(N)
RPUSH
key
RPUSH value RPUSH myList "Hello"
[value
...]
Description: Inserts the specified values at the tai
stored at key.Time Complexity: O(N)
LRANGE LRANGE
key LRANGE myList 0 -1
start
stop
Description: Returns the specified elements of the
key.Time Complexity: O(S+N) where S is the distanc
and N is the number of elements in the specified ra
LLEN
LLEN LLEN myList
key
Description: Returns the length of the list stored a
Complexity: O(1)
LPOP
LPOP key LPOP myList
[count]
Description: Removes and returns the first element
stored at key.Time Complexity: O(N)
RPOP
RPOP key RPOP myList
[count]
Description: Removes and returns the last element
stored at key.Time Complexity: O(N)
Streams
CLI node- redis- NRedisStack Jedis
redis py
Command Syntax
XADD key
field value
XADD XADD myStream *
[field value
...]
Description: Appends the specified stream entry t
adding a new entry.
XREAD
[COUNT
count]
[BLOCK
XREAD XREAD COUNT 2 ST
milliseconds]
STREAMS
key [key ...]
ID [ID ...]
Description: Read data from one or multiple stream
received ID reported by the caller.
XRANGE key
start end
XRANGE XRANGE myStream
[COUNT
count]
Description: Returns the entries matching a range
number of elements being returned. If N is constan
can consider it O(1).
XLEN XLEN key XLEN myStream
Description: Returns the number of entries of a str
XDEL key ID
XDEL XDEL myStream 15
[ID ...]
Description: Removes the specified entries from a
the stream
XTRIM key
XTRIM MAXLEN [~] XTRIM myStream M
count
Description: Trims the stream to a different length
entries. Constant times are very small however, sin
entries that can be released with a single dealloca
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
DEVELOPERS Docs Commands Tutorials University Demos
CLI node- redis- NRedisStack Jedis
redis py
On this page
Learn
Connect
Getting
Ge g Strings/Numbers
Started
Generic
Create Command Syntax
Develop Hashes
Commands Sets
cheat sheet JSON.SET key Sorted sets
Overview JSON.SET JSON.S
path value Lists
Java Streams
C Description: Sets JSON value at path in key.Time Co JSON
Node.js
Python Search and
JSON.GET key Query
.NET JSON.GET JSON.G
[path [path ...]]
Ruby
Deno Description: Returns the JSON value at path in key
Rust when path is evaluated to multiple values, where N
Explore
Operate
JSON.NUMINCRBY JSON.S
HowTos & JSON.NUMINCRBY
Tutorials key path number JSON.N
Guides
Redis Description: Increments a number inside a JSON do
University
multiple values, where N is the size of the key
JSON.OBJKEYS
JSON.OBJKEYS JSON.O
key [path]
Description: Return the keys in the object that's re
number of keys in the object, O(N) when path is ev
JSON.OBJLEN
JSON.OBJLEN JSON.O
key [path]
Description: Report the number of keys in the JSO
is evaluated to multiple values, where N is the size
JSON.ARRAPPEND JSON.S
JSON.ARRAPPEND key [path] value JSON.A
[value ...]
Description: Append the json values into the array
added where N is the size of the key
JSON.ARRINSERT
JSON.ARRINSERT key path index JSON.A
value [value ...]
Description: Insert the json values into the array at
value where N is the size of the array, O(N) when pa
JSON.ARRINDEX
JSON.ARRINDEX key path value JSON.A
[start [stop]]
Description: Searches for the first occurrence of a
size of the array, O(N) when path is evaluated to m
Search and Query
CLI node- redis- NRedisStack Jedis
redis py
Command
FT.CREATE index
[ON HASH | JSON]
[PREFIX count prefix [p
[FILTER {filter}]
FT.CREATE SCHEMA
field_name [AS alias] T
[NOINDEX]
...
Description: Create an index with the given specifi
FT.SEARCH index query
[FILTER numeric_field m
[RETURN count identifie
FT.SEARCH [SORTBY sortby [ ASC |
[LIMIT offset num]
[PARAMS nargs name valu
Description: Search the index with a query, returni
FT.AGGREGATE index query
[LOAD count field [fiel
[ GROUPBY nargs property
[ SORTBY nargs [ propert
FT.AGGREGATE [ APPLY expression AS n
[ LIMIT offset num]
[FILTER filter]
[ PARAMS nargs name val
Description: Run a search query on an index, and p
FT.INFO FT.INFO index
Description: Return information and statistics on t
FT.DROPINDEX FT.DROPINDEX index [DD]
Description: Dropping existing index.Time Complex
Join Redis University
Get Started with Redis
This path is designed for developers who
are new to Redis. Whether you’re ready to
start using Redis in production or just
interested in learning...
Get started
Last updated on Jan 31,
2025
Previous Next
Redis on Develop your
Heroku application
using
programming
languages
USE CASES INDUSTRIES COMPARE COMPANY
Vector database Financial Redis vs Mission &
Services Elasticache values
Feature stores
Gaming Redis vs Leadership
Trust Semantic cache Memcached
Healthcare Careers
Privacy Caching Redis vs
Retail Memory Store News
Terms of use NoSQL database
All industries Redis vs
Legal notices Leaderboards Source
Data Available
deduplication
Messaging CONNECT PARTNERS SUPPORT
Authentication Community Amazon Web Professional
token storage Services services
Events &
Fast-data ingest webinars Google Cloud Support
Query caching News Microsoft
Azure
All solutions All partners