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_passwordredis-cli PINGSend 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 PINGredis-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 redisredis-cli CLIENT LISTList current client connections (id, addr, fd, name, …).
CLIENT LIST; CLIENT GETNAME; CLIENT SETNAME
redis-cli CLIENT LIST | awk '{print $1, $2}' | headredis-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 -lKey & String
GET / SET / SETEX / SETNXRead / 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:42MSET / MGET / MSETNXMulti-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:1INCR / INCRBY / INCRBYFLOATAtomic 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.05APPEND / STRLEN / DEL / EXISTSCommon 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:42Key & TTL
EXPIRE / PEXPIRE / TTL / PTTL / PERSIST / EXPIREATSet / 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:42KEYS pattern / SCANKEYS 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 -20OBJECT 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:setHash
HSET / HGET / HMSET / HMGET / HGETALLStore 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:42HKEYS / HVALS / HLEN / HEXISTS / HDELNavigate 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 adminHINCRBY / HINCRBYFLOATAtomic 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.95List
LPUSH / RPUSH / LPOP / RPOPTreat 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:queueLRANGE / LLEN / LINDEX / LSET / LREMRead/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 -1BLPOP / BRPOP / BRPOPLPUSHBlocking 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 0RPOPLPUSH 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 LEFTSet
SADD / SMEMBERS / SCARD / SISMEMBERSet 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:42SREM / SPOP / SRANDMEMBERRemove, pop random (delete) or random pick (keep) — useful for sampling / lottery.
redis-cli SRANDMEMBER lottery:tickets 3 && redis-cli SPOP lottery:tickets 1SINTER / SUNION / SDIFF / SDIFFSTORESet 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:42Sorted Set (Zset)
ZADD / ZSCORE / ZRANGE / ZCARDStore 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 WITHSCORESZRANGEBYSCORE / ZRANK / ZINCRBY / ZREMRange/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 / UNSUBSCRIBERealtime 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 $PIDXADD / XLEN / XRANGE / XREADStream = 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 FLUSHDBDBSIZE / 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 REWRITESLOWLOG GET|len|resetInspect commands exceeding slowlog-log-slower-than (microseconds).
SLOWLOG GET 10; SLOWLOG LEN; SLOWLOG RESET
redis-cli SLOWLOG GET 10 | jq '.[].command'MONITORStream 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 DOCTORACL WHOAMI / ACL CAT / ACL GETUSERACL debugging (Redis 6+).
redis-cli ACL WHOAMI && redis-cli ACL GETUSER deployer | head -20Persistence
BGSAVE / SAVE / LASTSAVETrigger RDB snapshot (BGSAVE = fork+async); LASTSAVE returns last snapshot timestamp.
redis-cli BGSAVE && redis-cli LASTSAVEBGREWRITEAOFRewrite 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 | headREPLICAOF 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 ONEPipeline & Scanning
redis-cli ... < commands.txtPipelining: 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 | headredis-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 -lDiagnostics
redis-cli --bigkeys / --memkeysFind the largest keys / per-key memory; sample-based (won't freeze the server).
redis-cli -h prod --bigkeys --i 0.01 | tee /tmp/bigkeys.logredis-cli --latency / --latency-historyLive 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 %1redis-cli CLUSTER INFO / CLUSTER NODESCluster state: slots, node role (master/replica), state.
redis-cli --cluster check 10.0.0.1:6379Cheatsheet version 1.0.0
Covers Redis 6.2+