DevOpsil
Redis46 commands

Redis Cheat Sheet

Essential Redis commands for strings, hashes, lists, sets, pub/sub, TTLs, and cluster management.

Connection & Server

CommandDescription
redis-cli
Connect to local Redis
redis-cli -h host -p 6379 -a password
Connect to remote Redis
PING
Check if server is alive
INFO
Server info and statistics
INFO memory
Memory usage details
DBSIZE
Number of keys in current DB
FLUSHDB
Delete all keys in current DB
SELECT 1
Switch to database 1
CONFIG GET maxmemory
Get config value

Strings

CommandDescription
SET key value
Set a key
GET key
Get a key's value
SET key value EX 3600
Set with 1-hour TTL
SETNX key value
Set only if key doesn't exist
MSET k1 v1 k2 v2
Set multiple keys
MGET k1 k2
Get multiple keys
INCR counter
Increment integer value
INCRBY counter 5
Increment by specific amount
APPEND key " more"
Append to string value

Hashes

CommandDescription
HSET user:1 name "Alice" age 30
Set hash fields
HGET user:1 name
Get single hash field
HGETALL user:1
Get all hash fields and values
HDEL user:1 age
Delete hash field
HINCRBY user:1 age 1
Increment hash field
HEXISTS user:1 name
Check if hash field exists

Lists & Sets

CommandDescription
LPUSH queue job1 job2
Push to left of list
RPOP queue
Pop from right of list
LRANGE queue 0 -1
Get all list elements
LLEN queue
List length
SADD tags "devops" "cloud"
Add to set
SMEMBERS tags
Get all set members
SISMEMBER tags "devops"
Check set membership
SINTER set1 set2
Set intersection

Keys & TTL

CommandDescription
KEYS pattern*
Find keys by pattern
SCAN 0 MATCH user:* COUNT 100
Iterate keys (production-safe)
EXISTS key
Check if key exists
DEL key
Delete key
EXPIRE key 300
Set TTL (5 minutes)
TTL key
Check remaining TTL
PERSIST key
Remove TTL
TYPE key
Get key's data type
RENAME key newkey
Rename a key

Pub/Sub & Streams

CommandDescription
PUBLISH channel message
Publish message to channel
SUBSCRIBE channel
Subscribe to channel
XADD stream * field value
Add entry to stream
XREAD COUNT 10 STREAMS stream 0
Read from stream
XLEN stream
Stream length