2

I use Redis and ruby. There are records:

"phones:initial:#{id}"

redis.hset "phones:initial:1", "query", query
redis.hset "phones:initial:2", "query", query
redis.hset "phones:initial:3", "query", query
redis.hset "phones:initial:4", "query", query
...

is it possible to get the keys, in which id corresponds to a expression?

"phones:initial: and id % m = n

1 Answer 1

1

NO, there's no built-in method to do that. You have to use the SCAN command to iterate on all keys, and select those that match the given pattern.

However, if you always use the same m for the expression, you can pre-compute n for each id, and make n as a part of the key. In this way, you can use Redis' pattern match to get those specific keys.

For example, suppose m == 2, you can have the following new keys: phones:initial:1:1, phones:initial:0:2, phones:initial:1:3, phones:initial:0:4. To get keys that match phones:initial: and id % 2 == 0, use the following command: SCAN 0 MATCH phones:initial:0:*

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.