skip to Main Content

I want to use HSCAN match clause to match a key which is of type 1 or type 2. A regex would be like ^match1|^match2. Is it possible to do this in glob style pattern.

2

Answers


  1. Redis does not offer a straight forward way to match multiple patterns.
    Redis matchs using glob-style pattern which is very limited.

    Supported glob-style patterns:

    • h?llo matches hello, hallo and hxllo
    • h*llo matches hllo and heeeello
    • h[ae]llo matches hello and hallo, but not hillo
    • h[^e]llo matches hallo, hbllo, … but not hello
    • h[a-b]llo matches hallo and hbllo

    Use to escape special characters if you want to match them verbatim.

    Login or Signup to reply.
  2. You can’t use glob-style for that, but you can Lua your way around this. That means you can use
    EVAL and a script (can be similar to https://github.com/itamarhaber/redis-lua-scripts/blob/master/scanregex.lua) for performing the HSCAN match1* first, and then filtering with Lua on match2.*.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search