user2599052
user2599052

Reputation: 1136

How to write a redis scan command to match either of two patterns

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.

Upvotes: 2

Views: 1978

Answers (2)

Itamar Haber
Itamar Haber

Reputation: 49932

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.*.

Upvotes: 1

ziad
ziad

Reputation: 404

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.

Upvotes: 4

Related Questions