Redis command to get all available keys?
Updated for Redis 2.8 and above
As noted in the comments of previous answers to this question, KEYS
is a potentially dangerous command since your Redis server will be unavailable to do other operations while it serves it. Another risk with KEYS
is that it can consume (dependent on the size of your keyspace) a lot of RAM to prepare the response buffer, thus possibly exhausting your server's memory.
Version 2.8 of Redis had introduced the SCAN family of commands that are much more polite and can be used for the same purpose.
The CLI also provides a nice way to work with it:
$ redis-cli --scan --pattern '*'
Try to look at KEYS
command. KEYS *
will list all keys stored in redis.
EDIT: please note the warning at the top of KEYS
documentation page:
Time complexity: O(N) with N being the number of keys in the database, under the assumption that the key names in the database and the given pattern have limited length.
UPDATE (V2.8 or greater): SCAN
is a superior alternative to KEYS
, in the sense that it does not block the server nor does it consume significant resources. Prefer using it.