Skip to content

/flags/redis/redis-cli-scan

redis-cli --scan --pattern: list keys without blocking Redis

The commands on this page have not been executed by our verification runner yet.updated 2026-10-20
tool
Redis
command
redis-cli
flag
--scan [--pattern P] [--count N]
default
off

redis-cli --scan --pattern 'user:*' prints every matching key by calling SCAN repeatedly, a few keys at a time. Unlike KEYS user:*, which walks the whole keyspace in one command and blocks every other client until it finishes, SCAN keeps the server responsive, so it is the safe way to look for keys in production.

Examples

bash
redis-cli --scan --pattern 'session:*'                       # list matching keys
redis-cli --scan --pattern 'session:*' | wc -l               # count them
redis-cli --scan --pattern 'cache:*' --count 1000            # bigger batches (a hint, not a limit)
redis-cli --scan --type hash                                 # only hashes (Redis 6+)
redis-cli -n 2 --scan --pattern 'job:*'                      # database 2

Delete keys by pattern

bash
redis-cli --scan --pattern 'cache:*' | xargs -r -n 500 redis-cli UNLINK

UNLINK frees memory in the background, so it does not block like DEL on large values.

What SCAN guarantees

PropertySCANKEYS
Blocks the serverno, small stepsyes, for the whole keyspace
Returns keys present the whole timeyes, at least onceyes
Duplicates possibleyes, deduplicate if it mattersno
Keys added or removed during the scanmay or may not be returnedn/a
Safe on a big production instanceyesno

Sources