Search code examples
redisservicestack.redis

Redis HSCAN Multiple Match


Here is the hash set I have

HSET MySet 111222333 Tom
HSET MySet 444555666 Julia
HSET MySet 777888999 Paul 

You can think about the set field as a phone number, and the SET value as a person's name.

I need to get all records that contains "23" and "89" inside the phone number.

It's possible doing 2 requests and merge them on the server:

HSCAN MySet 0 MATCH *23*
HSCAN MySet 0 MATCH *89*

Can we do the same thing using one expression? Like this

HSCAN MySet 0 Match *23* OR *89*  
OR
HSCAN MySet 0 Match *23|89*  

Solution

  • Not directly - Redis does glob-style pattern matching and that's not really supported.

    What you could do is use a little bit of Lua magic to craft your own efficient filtering, similarly to the example in this answer: https://stackoverflow.com/a/29945372/3160475