There are two ways to get all keys from the all databases in Redis.
The first way is to list keys using
--scan option and the second one is to get all keys using the
Note that the first way of getting all keys is preferable as it doesn’t require the client to load all the keys into memory despite of the
KEYS command only when the key space is reasonably sized.
Cool Tip: Delete all keys from the all databases in Redis! Read more →
Get All Keys In Redis
Get all keys using the
$ redis-cli --scan --pattern '*'
List all keys using the
$ redis-cli KEYS '*'
5 Replies to “Redis: Get All Keys – Redis-CLI”
(error) ERR wrong number of arguments for ‘keys’ command
make sure to insert * after keys
redis-cli KEYS ‘*’ – this is the right one
Awesome! It worked.
KEYS is node scoped, so it won’t return what you expect in a redis cluster setup. Also it will block the cluster until all the keys have been checked against the pattern.
redis-cli –scan [-i 0.01] [–pattern some*pattern] is the right way since it won’t freeze the cluster and also find the keys on all nodes.