1

How can I find keys with multiple match pattern, for example I have keys with

foo:*, event:*, poi:* and article:* patterns.

How can I find keys with redis keys function for match with foo:* or poi:* pattern, its like

find all keys with prefix foo:* or poi:*
marc_s
759k185 gold badges1.4k silver badges1.5k bronze badges
asked Jan 6, 2014 at 11:33

1 Answer 1

1

You should not do this. KEYS is mainly a debug command. It is not supposed to be used for anything else.

Redis is not a database supporting ad-hoc queries: you are supposed to provide access paths for the data you put into Redis (using extra set or hash or zset indexes).

If you really need to run arbitrary boolean expressions on keys to select data, I would suggest to do it offline by using the rdb-redis-tools package.

answered Jan 6, 2014 at 12:42
Sign up to request clarification or add additional context in comments.

3 Comments

I agree with Didier. Since redis 2.8, you can use SCAN, which you can use for online scanning. However, that's not what you want your clients to use. Follow Didier's advice for that.
SCAN cursor MATCH pattern COUNT count i.e. SCAN 0 MATCH user:* COUNT 1000 check the docs for more specifics: redis.io/commands/scan
Keep in mind COUNT doesn't exactly mean what you may assume it does. Check the SCAN command docs mentioned above.

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.