Good afternoon everyone, I want to get all objects from Redis by mask or template. I know that I can use KEYS, but it is very slow, because it works for O(n), where n is the size of all keys in the database, and returns only keys without data. Can you offer me a good solution?
2
Answers
You can use SCAN https://redis.io/commands/scan or HGETALL command and store your objects in a hash table for details, I advise you to look at the documentation https://redis.io/commands/hgetall.
SCAN
is the suitable option for replacement ofKEYS *
coz of time complexity. But you can’t get the value of the key using this option. As you can use hash structure for this coz by usingHGETALL
you can retrieve all keys and values in a single call. These are the two options available for your case as @Qwe said. However I personally use bash script to get rid of these coz I don’t want to change my structure to hash. Like this.,I hope this will be heplfull.