0

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?

asked Jul 15, 2014 at 1:48
2
  • Can you explain what you need this for, so we can provide you a better answer? keys Test:* is the way to get keys with your prefix, but if you tell us what you need them for, we can give you alternative ways of doing what you want. Commented Jul 15, 2014 at 13:48
  • After I get keys matching pattern, I wanted to delete specific keys. and now I found easy way. stackoverflow.com/questions/4006324/… Thank you for your advice. Commented Jul 16, 2014 at 2:54

2 Answers 2

6

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

answered Jul 18, 2014 at 8:36
Sign up to request clarification or add additional context in comments.

Comments

2

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.

answered Jul 15, 2014 at 1:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.