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 '*'

4 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.

Leave a Reply