Redis does not use the keys command to get key value information

  • 2020-06-15 10:28:28
  • OfStack

1. Source of problem

This problem may seem strange, but many redis clusters have a unified entry that ACTS as a proxy for the redis command. Generally, the keys command is not allowed to obtain key information due to new considerations, but the scan command can be used instead of keys

2. Use the keys method


127.0.0.1:6379> KEYS *
1) "_kombu.binding.test_queue"
2) "a8e620b9-e52e-3498-8a1c-448f35783058"
3) "_kombu.binding.celery"

3. Use the scan method


127.0.0.1:6379> DBSIZE
(integer) 3
127.0.0.1:6379> SCAN 0 MATCH * COUNT 3
1) "5"
2) 1) "a8e620b9-e52e-3498-8a1c-448f35783058"
 2) "_kombu.binding.test_queue"
 3) "_kombu.binding.celery"

Simple instructions

The SCAN command (and the related SSCAN/HSCAN/ZSCAN, for SET/HASH/ZSET, respectively) is used for incremental traversal of elements in a collection. Because of its incremental nature (returning only 1 small number of elements at a time), it can be used instead of KEYS or SMEMBERS commands in a production environment (KEYS or SMEMBERS commands may block redis because they return too many elements)

So even if the redis service supports the keys command in a production environment, scan should be used instead

Reference:

1. https://groups.google.com/forum/#!topic/redis-db/zZeI_PjHF_M
2. https://redis.io/commands/scan

conclusion

Above is the site to introduce Redis does not use keys command to get key information related knowledge, I hope to help you, if you have any questions welcome to leave a message, this site will timely reply to you!


Related articles: