Redis command to get all available keys?

后端 未结 15 2657
攒了一身酷
攒了一身酷 2020-12-04 04:30

Is there a Redis command for fetching all keys in the database? I have seen some python-redis libraries fetching them. But was wondering if it is possible from redis-client.

15条回答
  •  遥遥无期
    2020-12-04 05:19

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

提交回复
热议问题