Look up Redis commands by name or data structure, with time complexity front and centre — because Redis is single threaded and an O(N) command blocks everyone.
20 commands
Search by name, by data structure, or by what it does.
Redis is single threaded. An O(N) command on a large key does not slow one request down — it blocks every other client until it finishes.
SCAN is not a drop-in for KEYS. It is cursor-based, may return the same key twice, and offers no snapshot. That is the price of not blocking the server.
Expiry is per key, not per field. A hash field cannot carry its own TTL; setting one on the hash expires the whole thing.
GETStringO(1)GET keyReads a string value.
SETStringO(1)SET key value [EX seconds] [NX|XX]Writes a string value.
`SET key value EX 60` sets the value and its expiry in one atomic step. Doing `SET` then `EXPIRE` leaves a window where a crash leaves the key immortal.
SETNXStringO(1)SETNX key valueSets only if the key does not exist.
Used for locks, and unsafe alone: a holder that dies never releases it. `SET key token NX EX 30` is the correct form, with a token so only the owner can delete it.
INCRStringO(1)INCR keyIncrements an integer stored as a string.
Atomic, which is what makes Redis a good counter and rate limiter. A missing key starts at 0.
EXPIREGenericO(1)EXPIRE key secondsSets a time to live.
Most write commands clear the TTL. A `SET` on a key with an expiry makes it permanent again unless you pass `KEEPTTL`.
TTLGenericO(1)TTL keySeconds remaining.
−1 means the key exists with no expiry; −2 means it does not exist. Confusing the two is a common bug.
DELGenericO(n) in elementsDEL key [key …]Removes keys.
Deleting one huge collection blocks the server while it frees every element. `UNLINK` does the same thing and frees in the background.
UNLINKGenericO(1) for the callerUNLINK key [key …]Removes keys, freeing memory asynchronously.
The one to use for large values. `DEL` on a multi-million-element set is a measurable stall.
KEYSGenericO(n) over the keyspaceKEYS patternEvery key matching a glob.
Never in production. Redis is single-threaded, so this blocks every other client until it finishes walking the entire keyspace. `SCAN` is the cursor-based equivalent that does not.
SCANGenericO(1) per callSCAN cursor [MATCH pattern] [COUNT n]Walks the keyspace a page at a time.
Guarantees every key present throughout the scan is returned at least once — so a key may appear twice, and one added during the scan may not appear at all.
HSETHashO(1) per fieldHSET key field value [field value …]Sets fields on a hash.
A hash is more memory-efficient than one key per field, and the whole hash shares one TTL — you cannot expire a single field.
HGETALLHashO(n)HGETALL keyEvery field and value.
Fine for a small hash, a problem for a large one, since it blocks while serialising everything. `HSCAN` pages through it.
LPUSHListO(1) per valueLPUSH key value [value …]Prepends to a list.
`LPUSH` with `BRPOP` is the classic simple queue. It loses a job if the worker dies after popping — `BLMOVE` into a processing list is the reliable version.
BRPOPListO(1)BRPOP key [key …] timeoutPops from the tail, waiting if empty.
Blocks the connection, not the server. A blocking command needs its own connection rather than one from a shared pool.
SADDSetO(1) per memberSADD key member [member …]Adds to a set.
Returns how many were actually new, which makes it a one-call way to test and set membership.
ZADDSorted setO(log n)ZADD key score member [score member …]Adds to a sorted set.
The structure behind leaderboards, rate limiters and delayed queues. Using a timestamp as the score makes range queries over time cheap.
ZRANGEBYSCORESorted setO(log n + m)ZRANGEBYSCORE key min max [LIMIT offset count]Members within a score range.
With a timestamp score this is how a delayed queue finds what is due.
MULTITransaction—MULTI … EXECQueues commands and runs them together.
Not a transaction in the SQL sense: there is no rollback. If one command fails the others still run. `WATCH` adds optimistic locking, and a Lua script is usually the better answer.
EVALScriptingDepends on the scriptEVAL script numkeys key [key …] arg [arg …]Runs a Lua script atomically.
The whole script runs with nothing interleaved, which makes it the right way to do read-then-write atomically. A slow script blocks the entire server for its duration.
FLUSHALLGenericO(n)FLUSHALLDeletes every key in every database.
No confirmation and no undo. The most destructive command here, and one keystroke from `FLUSHDB`.
Redis Command Reference runs entirely on your device — no Redis server is contacted.
You’re on the Free plan. Compare plans
Complexity is the column that matters here, because Redis runs commands one at a time. An O(N) command on a large key does not slow down one request — it blocks every other client for as long as it takes. `KEYS *` on a production instance is the canonical example, and `SMEMBERS` on a large set, `HGETALL` on a large hash and `FLUSHALL` are the same shape of mistake.
`SCAN` is the answer to `KEYS`, and it is not a drop-in replacement. It is cursor-based, may return the same key more than once, and offers no snapshot guarantee — those are the costs of not blocking the server. A reference that recommends SCAN without saying so sets people up to be surprised by duplicates.
Expiry is per key, never per field. A hash field cannot carry its own TTL, and setting one on the hash expires the whole thing. People model around this with separate keys, and discovering the rule after writing the hash is the expensive way to learn it.
The data structures are where the real design decisions live. A sorted set gives you ordering and range queries at a cost in memory; a list is cheap at both ends and expensive in the middle; a hash is the right shape for an object and the wrong one for anything you need to expire piecemeal.
Nothing is connected. No Redis server is contacted, and the reference says nothing about what is in yours.
Because it is O(N) over the whole keyspace and Redis is single threaded. On a few million keys it blocks every other client for seconds. SCAN does the same job incrementally.
No. It is cursor-based, can return the same key twice across iterations, and gives no point-in-time guarantee — keys added or removed during the scan may or may not appear. That is the price of not blocking.
Not in most deployments. TTL is a property of a key, so expiring a hash expires all of it. If fields need independent lifetimes, they need to be separate keys.
When you need ordering by a score with range queries — leaderboards, time series, priority queues. It costs more memory than a plain set, and `ZRANGEBYSCORE` is the reason you pay it.
No. It is an offline reference. No server is contacted and nothing is executed.