📖 Guide

Redis Commands Cheat Sheet — Complete Reference

Every Redis command you need, from strings and hashes to streams and clusters. Searchable and organized.

200 commands across 12 categories

Connection & Server

CommandDescription
redis-cli
Connect to local Redis on default port 6379
redis-cli -h <host> -p <port>
Connect to a remote Redis instance
redis-cli -a <password>
Connect with authentication
redis-cli -n <db>
Connect to a specific database number
redis-cli --tls
Connect over TLS
AUTH <password>
Authenticate to the server
AUTH <username> <password>
Authenticate with username (Redis 6+ ACL)
PING
Test if server is alive (returns PONG)
SELECT <db>
Switch to a different database (0-15)
DBSIZE
Return the number of keys in the current database
INFO
Get server information and statistics
INFO memory
Get memory usage statistics
CONFIG GET <pattern>
e.g. CONFIG GET maxmemory
Get configuration parameters
CONFIG SET <key> <value>
Set a configuration parameter at runtime
CONFIG REWRITE
Persist runtime config changes to redis.conf
FLUSHDB
Delete all keys in the current database
FLUSHALL
Delete all keys in all databases
SAVE
Synchronous save (blocks server)
BGSAVE
Background save (non-blocking)
LASTSAVE
Get the timestamp of the last successful save
MONITOR
Stream all commands received by the server in real time
SLOWLOG GET 10
Get the 10 most recent slow queries
CLIENT LIST
List all connected clients
CLIENT KILL ID <id>
Kill a specific client connection
SHUTDOWN
Shut down the server

Strings

CommandDescription
SET key value
Set a string value
SET key value EX 60
Set with expiry in seconds
SET key value PX 5000
Set with expiry in milliseconds
SET key value NX
Set only if key does not exist
SET key value XX
Set only if key already exists
SETNX key value
Set if not exists (returns 1 on success, 0 if exists)
SETEX key 60 value
Set value with expiry in seconds (atomic)
MSET key1 val1 key2 val2
Set multiple keys at once
MSETNX key1 val1 key2 val2
Set multiple keys only if none exist
GET key
Get the value of a key
MGET key1 key2 key3
Get values of multiple keys
GETSET key value
Set new value and return the old one
GETDEL key
Get value and delete the key
GETRANGE key 0 4
Get a substring of the value
SETRANGE key 6 world
Overwrite part of a string at offset
STRLEN key
Get the length of the value
APPEND key " extra"
Append to existing value
INCR key
Increment integer value by 1
INCRBY key 5
Increment integer value by N
INCRBYFLOAT key 1.5
Increment float value
DECR key
Decrement integer value by 1
DECRBY key 3
Decrement integer value by N

Hashes

CommandDescription
HSET key field value
Set a field in a hash
HSET key f1 v1 f2 v2
Set multiple fields at once (Redis 4+)
HSETNX key field value
Set field only if it doesn't exist
HGET key field
Get a field value
HMGET key f1 f2 f3
Get multiple field values
HGETALL key
Get all fields and values
HDEL key field
Delete one or more fields
HEXISTS key field
Check if a field exists (returns 0 or 1)
HLEN key
Get number of fields in the hash
HKEYS key
Get all field names
HVALS key
Get all values
HINCRBY key field 5
Increment integer field value
HINCRBYFLOAT key field 1.5
Increment float field value
HSCAN key 0 MATCH user:*
Incrementally iterate hash fields

Lists

CommandDescription
LPUSH key value
Push element to the head (left) of a list
RPUSH key value
Push element to the tail (right) of a list
LPUSH key v1 v2 v3
Push multiple elements to the head
LPUSHX key value
Push to head only if list exists
RPUSHX key value
Push to tail only if list exists
LPOP key
Remove and return element from head
RPOP key
Remove and return element from tail
LPOP key 3
Pop multiple elements from head (Redis 6.2+)
BLPOP key 30
Blocking pop from head (wait up to 30s)
BRPOP key 30
Blocking pop from tail (wait up to 30s)
LLEN key
Get the length of a list
LRANGE key 0 -1
Get all elements (start to end)
LRANGE key 0 9
Get first 10 elements
LINDEX key 0
Get element at a specific index
LSET key 0 newvalue
Set element at a specific index
LINSERT key BEFORE pivot value
Insert before a pivot element
LREM key 2 value
Remove first 2 occurrences of value
LTRIM key 0 99
Trim list to specified range (keep 100 items)
RPOPLPUSH source dest
Pop from tail of source, push to head of dest
LMOVE src dst LEFT RIGHT
Move element between lists (Redis 6.2+)

Sets

CommandDescription
SADD key member
Add one or more members to a set
SADD key m1 m2 m3
Add multiple members
SREM key member
Remove one or more members
SISMEMBER key member
Check if member exists (returns 0 or 1)
SMISMEMBER key m1 m2 m3
Check if multiple members exist (Redis 6.2+)
SMEMBERS key
Get all members
SCARD key
Get the number of members
SPOP key
Remove and return a random member
SPOP key 3
Remove and return N random members
SRANDMEMBER key
Get a random member without removing
SUNION key1 key2
Return union of sets
SUNIONSTORE dest key1 key2
Store union into a new set
SINTER key1 key2
Return intersection of sets
SINTERSTORE dest key1 key2
Store intersection into a new set
SDIFF key1 key2
Return difference (members in key1 not in key2)
SDIFFSTORE dest key1 key2
Store difference into a new set
SMOVE source dest member
Move a member from one set to another
SSCAN key 0 MATCH pattern*
Incrementally iterate set members

Sorted Sets

CommandDescription
ZADD key score member
Add member with score to sorted set
ZADD key 1 a 2 b 3 c
Add multiple members with scores
ZADD key NX score member
Add only if member doesn't exist
ZADD key GT score member
Update score only if new score is greater
ZINCRBY key 5 member
Increment score of a member
ZSCORE key member
Get the score of a member
ZMSCORE key m1 m2
Get scores of multiple members (Redis 6.2+)
ZRANK key member
Get rank (0-based, low to high)
ZREVRANK key member
Get rank (0-based, high to low)
ZRANGE key 0 -1
Get all members sorted by score (ascending)
ZRANGE key 0 -1 WITHSCORES
Get all members with their scores
ZREVRANGE key 0 9
Get top 10 by score (descending)
ZRANGEBYSCORE key 10 100
Get members with score between 10 and 100
ZRANGEBYSCORE key -inf +inf LIMIT 0 10
Get first 10 by score range
ZREM key member
Remove one or more members
ZREMRANGEBYRANK key 0 4
Remove members by rank range
ZREMRANGEBYSCORE key 0 100
Remove members by score range
ZCARD key
Get the number of members
ZCOUNT key 10 100
Count members with score in range
ZUNIONSTORE dest 2 key1 key2
Store union of sorted sets
ZINTERSTORE dest 2 key1 key2
Store intersection of sorted sets
ZPOPMIN key
Remove and return member with lowest score
ZPOPMAX key
Remove and return member with highest score
BZPOPMIN key 30
Blocking pop of lowest-scored member
ZSCAN key 0 MATCH pattern*
Incrementally iterate sorted set

Keys & Expiry

CommandDescription
KEYS *
Find all keys (avoid in production — blocks server)
KEYS user:*
Find keys matching a glob pattern
SCAN 0 MATCH user:* COUNT 100
Incrementally iterate keys (production-safe)
EXISTS key
Check if a key exists (returns 0 or 1)
TYPE key
Get the data type of a key
OBJECT ENCODING key
Get the internal encoding of a key
DEL key
Delete one or more keys (blocking)
UNLINK key
Delete keys asynchronously (non-blocking)
RENAME key newkey
Rename a key
RENAMENX key newkey
Rename only if new key doesn't exist
COPY source dest
Copy value to another key (Redis 6.2+)
DUMP key
Serialize a key's value
RESTORE key 0 <serialized>
Restore a serialized value
EXPIRE key 60
Set TTL in seconds
PEXPIRE key 5000
Set TTL in milliseconds
EXPIREAT key 1700000000
Set expiry as Unix timestamp
PERSIST key
Remove expiry (make key persistent)
TTL key
Get remaining TTL in seconds (-1 = no expiry, -2 = missing)
PTTL key
Get remaining TTL in milliseconds
RANDOMKEY
Return a random key from the database
SORT key ALPHA
Sort elements alphabetically
SORT key LIMIT 0 10 DESC
Sort numerically, descending, with limit

Pub/Sub

CommandDescription
SUBSCRIBE channel
Subscribe to a channel
SUBSCRIBE ch1 ch2 ch3
Subscribe to multiple channels
PSUBSCRIBE pattern*
Subscribe to channels matching a pattern
PUBLISH channel message
Publish a message to a channel
UNSUBSCRIBE channel
Unsubscribe from a channel
PUNSUBSCRIBE pattern*
Unsubscribe from a pattern
PUBSUB CHANNELS
List active channels with subscribers
PUBSUB NUMSUB channel
Get subscriber count for a channel
PUBSUB NUMPAT
Get total number of pattern subscriptions

Transactions

CommandDescription
MULTI
Start a transaction block
EXEC
Execute all commands in the transaction
DISCARD
Discard all commands in the transaction
WATCH key
Watch keys for changes (optimistic locking)
UNWATCH
Unwatch all watched keys
MULTI\nSET k1 v1\nSET k2 v2\nEXEC
Complete transaction example

Scripting

CommandDescription
EVAL "return redis.call('GET', KEYS[1])" 1 mykey
Execute a Lua script
EVAL "redis.call('SET', KEYS[1], ARGV[1])" 1 key value
Lua script with keys and arguments
EVALSHA <sha1> 1 mykey
Execute a cached script by SHA1 hash
SCRIPT LOAD "return 'hello'"
Load a script into cache and return its SHA1
SCRIPT EXISTS <sha1>
Check if a script exists in the cache
SCRIPT FLUSH
Remove all scripts from the cache
FUNCTION LOAD "#!lua name=mylib\nredis.register_function('myfunc', function(keys, args) return 'ok' end)"
Load a library function (Redis 7+)
FCALL myfunc 0
Call a registered function (Redis 7+)

Streams

CommandDescription
XADD stream * field value
Add entry with auto-generated ID
XADD stream * name John age 30
Add entry with multiple fields
XADD stream MAXLEN ~ 1000 * field value
Add entry with stream cap (~approximate)
XLEN stream
Get the number of entries in a stream
XRANGE stream - +
Get all entries (oldest to newest)
XRANGE stream - + COUNT 10
Get first 10 entries
XREVRANGE stream + -
Get all entries (newest to oldest)
XREAD COUNT 5 STREAMS stream 0
Read entries from the beginning
XREAD BLOCK 5000 STREAMS stream $
Block-read for new entries (5s timeout)
XGROUP CREATE stream group 0
Create a consumer group from the beginning
XGROUP CREATE stream group $ MKSTREAM
Create group for new entries only, create stream if missing
XREADGROUP GROUP group consumer COUNT 10 STREAMS stream >
Read pending entries for a consumer
XACK stream group <id>
Acknowledge a message
XPENDING stream group
Show pending entries summary
XCLAIM stream group consumer 60000 <id>
Claim idle pending messages
XDEL stream <id>
Delete a specific entry
XTRIM stream MAXLEN ~ 1000
Trim stream to approximate max length
XINFO STREAM stream
Get stream information
XINFO GROUPS stream
List consumer groups

Cluster

CommandDescription
redis-cli --cluster create host1:6379 host2:6379 host3:6379 --cluster-replicas 1
Create a new cluster with replicas
CLUSTER INFO
Get cluster state and information
CLUSTER NODES
List all nodes in the cluster
CLUSTER SLOTS
Get mapping of slots to nodes
CLUSTER MEET <ip> <port>
Add a node to the cluster
CLUSTER FORGET <node-id>
Remove a node from the cluster
CLUSTER REPLICATE <node-id>
Make current node a replica of another
CLUSTER FAILOVER
Manual failover (replica promotes itself)
CLUSTER RESET
Reset cluster configuration on a node
redis-cli --cluster reshard host:6379
Reshard slots between nodes
redis-cli --cluster check host:6379
Check cluster health
redis-cli -c
Connect in cluster mode (auto-redirect)

More Guides

🌿
Git Commands
Complete Git command reference — from basics to advanced workflows. Searchable, with examples.
📝
Vim Commands
Complete Vim/Vi command reference — modes, motions, editing, search, and advanced features.
🐳
Docker Commands
Complete Docker & Docker Compose command reference — containers, images, volumes, networks, and orchestration.
🔤
Regex Reference
Complete regular expression reference — syntax, patterns, quantifiers, groups, lookaheads, and common recipes.
🐧
Linux Commands
Complete Linux/Bash command reference — file management, text processing, networking, system admin, and shell scripting.
☸️
Kubernetes Commands
Complete Kubernetes & kubectl command reference — pods, deployments, services, configmaps, and cluster management.
🐍
Python Reference
Complete Python reference — syntax, data structures, string methods, file I/O, comprehensions, and common patterns.
🗃️
SQL Reference
Complete SQL reference — queries, joins, aggregation, subqueries, indexes, and database management.
🌐
Nginx Reference
Complete Nginx configuration reference — server blocks, locations, proxying, SSL, load balancing, and caching.
🔐
SSH Commands
Complete SSH reference — connections, key management, tunneling, config, SCP/SFTP, and security hardening.
👷
Jenkins Reference
Complete Jenkins reference — pipeline syntax, Jenkinsfile, plugins, CLI, agents, and CI/CD patterns.
☁️
AWS CLI Reference
Complete AWS CLI reference — EC2, S3, IAM, Lambda, ECS, RDS, CloudFormation, and common operations.
🐹
Go Reference
Complete Go (Golang) reference — syntax, types, functions, concurrency, error handling, and common patterns.
💠
PowerShell Reference
Complete PowerShell reference — cmdlets, pipelines, scripting, file operations, remote management, and Active Directory.
🏗️
Terraform Commands
Complete Terraform reference — init, plan, apply, state management, modules, workspaces, and HCL syntax.
⚙️
Ansible Commands
Complete Ansible reference — playbooks, modules, inventory, roles, vault, and ad-hoc commands.

📖 Free, searchable command reference. Bookmark this page for quick access.