Cheatsheet: Redis
Last updated 2026-09-28
redis-cli Basics
Connect to a local server
Connect to a remote host/port with auth
Run one command non-interactively
Ping the server
List all keys matching a pattern (avoid in production; use SCAN)
Iterate keys without blocking the server
Delete a key / check if a key exists
Switch logical database (0-15 by default)
Flush the current database (deletes everything in it)
Strings & Expiration
Set / get a string value
Set only if the key doesn't exist, with a 30s expiration (atomic lock pattern)
Increment / decrement a numeric value
Increment by a specific amount
Set an expiration (seconds) on an existing key
Check remaining time-to-live
Remove expiration, making a key persist forever
Set multiple keys at once
Hashes
Set one or more fields on a hash
Get one field / all fields
Check if a field exists / delete a field
Increment a numeric field
List all field names / all values
Lists, Sets & Sorted Sets
Push to the left/right of a list
Read a range of a list (0 -1 = whole list)
Pop from the left/right (blocking variants: BLPOP/BRPOP)
Add members to a set / check membership
Set intersection / union / difference
Add a member with a score to a sorted set
Read a sorted set by rank, or by score range
Get a member's rank or score
Pub/Sub
Subscribe to a channel (blocks in the CLI)
Publish a message to a channel
Subscribe to channels matching a glob pattern
Unsubscribe from a channel
Persistence, Replication & Info
Trigger a synchronous RDB snapshot (blocks the server)
Trigger a background (non-blocking) RDB snapshot
Rewrite the AOF file to compact it
Make this instance a replica of another
Promote a replica back to primary
Show server info (memory, replication, persistence, stats)
Show and reload live config values