All cheatsheets

Redis CLI Cheat Sheet

Quick reference for redis-cli: connection & info, key/string commands, hashes, lists, sets, sorted sets, streams, pub/sub, server management, persistence & replication and diagnostics — with common options and practical examples.

42 commands

Connection & Info

redis-cli -h <host> -p <port> -a <pwd>

Connect to a Redis server and open an interactive REPL.

-h host; -p 6379; -a password; --user user; --pass password; --tls; --insecure; -n dbnum

redis-cli -h redis.internal -p 6379 --user monitoring --pass ***
redis-cli AUTH <password>

Authenticate to the current connection (after opening the REPL).

--user <user> && AUTH password; ACL style

redis-cli AUTH my_secret_password
redis-cli PING

Send a PING; should reply PONG — basic connectivity / health probe.

any connect option, e.g. -h / -p / --pass; -r repeat; -i interval

redis-cli -h redis -p 6379 -i 5 PING
redis-cli INFO [section]

Show server statistics (server / clients / memory / replication / keyspace / stats / …).

INFO [server|clients|memory|stats|replication|keyspace|cluster|commandstats]; --stat simple live counter

redis-cli -h redis INFO memory | head && redis-cli --stat -i 5 -h redis
redis-cli CLIENT LIST

List current client connections (id, addr, fd, name, …).

CLIENT LIST; CLIENT GETNAME; CLIENT SETNAME

redis-cli CLIENT LIST | awk '{print $1, $2}' | head
redis-cli CLIENT KILL <id|addr>

Disconnect a client (by id, addr host:port, TYPE / ADDR / USER / LADDR filters).

KILL ADDR ip:port; KILL TYPE normal|master|replica|pubsub; KILL USER username

redis-cli CLIENT KILL ADDR 10.0.1.42:54321 && redis-cli CLIENT LIST | wc -l

Key & String

GET / SET / SETEX / SETNX

Read / write string values; SETEX adds TTL, SETNX writes only if missing.

SET key val EX N (TTL seconds) | PX N (ms) | NX/XX; GETEX (Redis 6.2)

redis-cli SET session:42 '{"user":42}' EX 3600 NX && redis-cli GET session:42
MSET / MGET / MSETNX

Multi-key string operations; MSETNX rejects if any key exists.

redis-cli MSET cache:hit:1 ok cache:hit:2 ok && redis-cli MGET cache:hit:1 cache:hit:2 cache:miss:1
INCR / INCRBY / INCRBYFLOAT

Atomic counter operations — perfect for rate limiters & counters.

redis-cli INCR ratelimit:user:42 redis-cli INCRBY hitcounter:2026-07-23 5 redis-cli INCRBYFLOAT metric:load 0.05
APPEND / STRLEN / DEL / EXISTS

Common string key management: append text, length, single/multi delete.

DEL key [key ...]; EXISTS k1 k2 (count of existing); TYPE key

redis-cli APPEND log:42 'request\n' && redis-cli STRLEN log:42

Key & TTL

EXPIRE / PEXPIRE / TTL / PTTL / PERSIST / EXPIREAT

Set / inspect TTLs (seconds vs millis vs absolute Unix time); PERSIST clears.

EXPIRE key seconds; PEXPIRE key ms; EXPIREAT key unix_seconds; NX/XX/GT/LT

redis-cli EXPIRE session:42 300 && redis-cli TTL session:42
KEYS pattern / SCAN

KEYS is O(N) and dangerous on large dbs — prefer SCAN with cursor.

SCAN cursor MATCH pattern COUNT N TYPE type; --no-warnings

redis-cli --scan --pattern 'cache:hit:*' | head -20
OBJECT ENCODING|HELP|FREQ|IDLETIME|REFCOUNT <key>

Inspect internal encoding, memory & last access (debug & RDS-tier tuning).

redis-cli OBJECT ENCODING big:set && redis-cli OBJECT IDLETIME big:set

Hash

HSET / HGET / HMSET / HMGET / HGETALL

Store a small object as a hash — great for profiles, configs, sessions.

HSET key f1 v1 f2 v2; HMGET key f1 f2; HSETNX f v set only if missing

redis-cli HMSET user:42 name Alice email [email protected] && redis-cli HGETALL user:42
HKEYS / HVALS / HLEN / HEXISTS / HDEL

Navigate and trim a hash: list keys/values, length, presence, deletion.

redis-cli HKEYS user:42 && redis-cli HLEN user:42 && redis-cli HEXISTS user:42 admin
HINCRBY / HINCRBYFLOAT

Atomic counter on a hash field — perfect for nested count metrics.

redis-cli HINCRBY orders:2026-07-23 paid_count 1 && redis-cli HINCRBYFLOAT orders:2026-07-23 gmv 19.95

List

LPUSH / RPUSH / LPOP / RPOP

Treat a list as a queue (LPUSH/LPOP = FIFO) or stack (LPUSH/RPOP = queue with backoff).

redis-cli RPUSH jobs:queue job1 job2 job3 && redis-cli LPOP jobs:queue
LRANGE / LLEN / LINDEX / LSET / LREM

Read/manage ranges of a list; LSET requires index; LREM count>0 from head, <0 from tail.

LRANGE key 0 -1 all; LINDEX 0 head; LREM 0 value all; LTRIM start stop keep range

redis-cli LRANGE jobs:queue 0 -1 && redis-cli LTRIM logs:2026-07-23 -1000 -1
BLPOP / BRPOP / BRPOPLPUSH

Blocking variants — pop if empty and wait N seconds; safe queue workers.

BLPOP key timeout (seconds, 0 = forever); COUNT option in Redis 6.2+

redis-cli BLPOP jobs:queue 0
RPOPLPUSH src dst / LMOVE src dst LEFT|RIGHT (6.2+)

Atomic pop from one side and push to another — secure queue processing.

redis-cli LMOVE jobs:queue jobs:processing RIGHT LEFT

Set

SADD / SMEMBERS / SCARD / SISMEMBER

Set operations: membership, size, bulk check (returns 0/1).

SADD k m1 m2 ...; SCARD k; SISMEMBER k m

redis-cli SADD tags:42 redis postgres mongo && redis-cli SCARD tags:42
SREM / SPOP / SRANDMEMBER

Remove, pop random (delete) or random pick (keep) — useful for sampling / lottery.

redis-cli SRANDMEMBER lottery:tickets 3 && redis-cli SPOP lottery:tickets 1
SINTER / SUNION / SDIFF / SDIFFSTORE

Set algebra — compute intersections, unions, differences; *_STORE writes to a key.

redis-cli SINTER tags:a tags:b tags:c && redis-cli SDIFFSTORE missing:set tags:all tags:42

Sorted Set (Zset)

ZADD / ZSCORE / ZRANGE / ZCARD

Store members with scores; ZRANGE works in score (WITHSCORES) or lex order.

ZADD k score m [score m ...]; ZRANGEBYSCORE -inf +inf; ZREVRANGE

redis-cli ZADD lb:game alice 1500 bob 1300 carol 1750 && redis-cli ZRANGE lb:game 0 -1 REV WITHSCORES
ZRANGEBYSCORE / ZRANK / ZINCRBY / ZREM

Range/rank/counter on zsets — top-N, lower-bound slides, leaderboards.

ZRANGEBYSCORE min max LIMIT offset count; ZREVRANK; ZREM k m [m...]

redis-cli ZADD ratelimit:api 1750731000.123 10.0.1.42 1750731050.456 10.0.1.7 && redis-cli ZREMRANGEBYSCORE ratelimit:api 0 $(date +%s.%N --date='-5 minutes')

Pub/Sub & Streams

SUBSCRIBE / PSUBSCRIBE / PUBLISH / UNSUBSCRIBE

Realtime pub/sub on the wire — lightweight broadcast, no persistence.

PSUBSCRIBE news:*; PUBLISH channel msg; PUB/SUB NUMSUB to inspect

redis-cli PSUBSCRIBE 'app.*' & PID=$!; redis-cli PUBLISH app.notice 'red-button pressed'; sleep 0.1; kill $PID
XADD / XLEN / XRANGE / XREAD

Stream = append-only log with consumer groups (Redis 5+).

XADD k * f v; XADD k MAXLEN ~ 1000 * f v (capped); XREAD / XREADGROUP; consumer names; XAUTOCLAIM

redis-cli XADD events * user 42 action click && redis-cli XLEN events && redis-cli XRANGE events - +
XREAD BLOCK 0 STREAMS k $

Block forever waiting for new entries — pair with consumer groups for worker queues.

redis-cli XGROUP CREATE events grp1 0 MKSTREAM && redis-cli XREADGROUP GROUP grp1 c1 BLOCK 0 COUNT 10 STREAMS events '>'

Server Mgmt

FLUSHDB / FLUSHALL [ASYNC]

Wipe the current (FLUSHDB) or all (FLUSHALL) databases. ⚠️ destructive.

FLUSHALL ASYNC; FLUSHDB ASYNC; --no-auth-warning

redis-cli -h dev FLUSHDB
DBSIZE / CONFIG GET|SET <key>

Inspect key count and runtime configuration (memory limits, appendonly, etc.).

CONFIG GET dir/save/maxmemory; CONFIG SET maxmemory 1gb; CONFIG REWRITE persist

redis-cli CONFIG SET maxmemory-policy allkeys-lru && redis-cli CONFIG REWRITE
SLOWLOG GET|len|reset

Inspect commands exceeding slowlog-log-slower-than (microseconds).

SLOWLOG GET 10; SLOWLOG LEN; SLOWLOG RESET

redis-cli SLOWLOG GET 10 | jq '.[].command'
MONITOR

Stream of every command executed by every client — debug only, very expensive.

no extra flags; --bigkeys (best with redis-cli --bigkeys); --memkeys; --latency; --intrinsic-latency

timeout 2 redis-cli MONITOR | grep -E 'EXPIRE|GET.*:42'
DEBUG ... / MEMORY USAGE <key>

Inspect internals: OBJECT encoding, memory per key (debug-only flags).

MEMORY USAGE key [SAMPLES N]; DEBUG OBJECT-DURATION or DEBUG RELOAD-ALL-COMMANDS (rare)

redis-cli MEMORY USAGE user:42 SAMPLES 5 && redis-cli MEMORY DOCTOR
ACL WHOAMI / ACL CAT / ACL GETUSER

ACL debugging (Redis 6+).

redis-cli ACL WHOAMI && redis-cli ACL GETUSER deployer | head -20

Persistence

BGSAVE / SAVE / LASTSAVE

Trigger RDB snapshot (BGSAVE = fork+async); LASTSAVE returns last snapshot timestamp.

redis-cli BGSAVE && redis-cli LASTSAVE
BGREWRITEAOF

Rewrite the AOF file in the background (compaction).

Rewrite still blocks briefly; auto is triggered by auto-aof-rewrite-percentage

redis-cli BGREWRITEAOF && redis-cli INFO persistence | head
REPLICAOF host port (was SLAVEOF)

Make this instance a replica of another (or REPLICAOF NO ONE to promote).

redis-cli REPLICAOF redis-master 6379 && redis-cli REPLICAOF NO ONE

Pipeline & Scanning

redis-cli ... < commands.txt

Pipelining: pipe commands from stdin to a single round-trip — much faster for batch.

--pipe mode uses RESP; < file.txt

printf 'SET k1 v1\nSET k2 v2\nGET k1\nGET k2\nINCR counter\n' | redis-cli --pipe | head
redis-cli --scan --pattern '...'

Server-side cursor scan, no O(N) blow-up like KEYS.

--scan --pattern p; --bigkeys / --memkeys / --hotkeys (sampling)

redis-cli --scan --pattern 'session:*' | wc -l

Diagnostics

redis-cli --bigkeys / --memkeys

Find the largest keys / per-key memory; sample-based (won't freeze the server).

redis-cli -h prod --bigkeys --i 0.01 | tee /tmp/bigkeys.log
redis-cli --latency / --latency-history

Live latency histogram (min / max / avg) over a few samples.

--latency; --latency-history -i 5; --intrinsic-latency N (diagnose the OS clock)

redis-cli -h prod --latency-history -i 5 > /tmp/lat.log & sleep 30; kill %1
redis-cli CLUSTER INFO / CLUSTER NODES

Cluster state: slots, node role (master/replica), state.

redis-cli --cluster check 10.0.0.1:6379

Cheatsheet version 1.0.0

Covers Redis 6.2+