← All cheatsheets

Databases

Redis — the redis-cli commands that come up daily

## Connect
`redis-cli -h host -p 6379` — connect
`redis-cli -h host -p 6379 -a password` — with auth
`redis-cli --tls -h host` — TLS
`PING` — test
`SELECT 0` — switch DB index

## Strings
`SET key value` / `GET key` — basic
`SET key value EX 60` — set with 60s TTL
`INCR counter` / `DECR counter` — atomic counter
`MGET key1 key2 key3` — get multiple

## Hashes
`HSET hash field value` — set field
`HGET hash field` / `HGETALL hash` — read

## Lists + sets
`LPUSH list value` / `RPUSH list value` — push left/right
`LRANGE list 0 -1` — read full list
`SADD set value` / `SMEMBERS set` — set ops

## Sorted sets (great for ranking)
`ZADD set score member` — add with score
`ZRANGE set 0 -1 WITHSCORES` — list ordered

## TTL + expiry
`EXPIRE key 60` — set TTL to 60s
`TTL key` — get remaining TTL
`PERSIST key` — remove TTL

## Inspect + admin
`KEYS pattern` — find keys (avoid in production; use SCAN)
`SCAN 0 MATCH pattern* COUNT 1000` — non-blocking scan
`DBSIZE` — total keys
`INFO` / `INFO memory` — server stats
`MEMORY USAGE key` — memory for one key
`MONITOR` — live command stream (development only)