Reputation: 109
I want to get key matching pattern.
ex) Test:*
I consider Keys command. but Its time complexity is too long.
ex) keys Test: * => It occurs overhead.
My Redis version is 2.6.16
There is another way?
Upvotes: 0
Views: 10856
Reputation: 18504
Please upgrade to latest Redis version (2.8.13) and use the SCAN
command instead that allows you to do the same as KEYS but without blocking the server. Also it is a good idea to think at alternative designs not involving full-scan of the key space. For example the new ZRANGEBYLEX command is able to perform lexicographic range queries on sorted sets.
Scan command documentation: http://redis.io/commands/scan
Upvotes: 6
Reputation: 132018
It depends on the problem you are trying to solve. I do something similar where I keep a SET of the keys I am interested in and first read that SET with smembers
then read the data for those keys. As far as search keys after the fact, you are already doing it as fast as redis can.
Of course you can update your code like I describe, generate that list via keys Test:*
and add each to the existing SET.
Upvotes: 2