Redis: Get All Keys – Redis-CLI

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 KEYS command.

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.

Use 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 --scan option:

$ redis-cli --scan --pattern '*'

List all keys using the KEYS command:

$ redis-cli KEYS '*'

5 Replies to “Redis: Get All Keys – Redis-CLI”

  1. (error) ERR wrong number of arguments for ‘keys’ command

    1. make sure to insert * after keys
      keys *

    2. redis-cli KEYS ‘*’ – this is the right one

      1. Awesome! It worked.

  2. 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.
    https://redis.io/docs/manual/cli/#getting-a-list-of-keys

Leave a Reply