Redis 或签入 MATCH
问题描述:
作为初学者,我想知道是否有办法在redis中编写下面的查询
As a beginner, I would like to know if there is a way to write below query in redis
Scan 0 MATCH Test:[keyword*:* | *:keyword]
现在我必须对这个查询进行两次单独的扫描,如下所示
Right now I have to do two separate scans for this query as below
Scan 0 MATCH Test:*:keyword*
Scan 0 MATCH Test:keyword*:*
答
我看到您在这里有 3 个选择:
I see that you've 3 choices here:
将两个命令包装到一个 Lua 脚本中,并像调用单个命令一样调用它.
Wrap both commands into a Lua script and call it as it would be a single command.
不要扫描,而是索引.创建一个 set 或 sorted set,您将在其中存储与这些模式匹配的所有元素,然后执行 aa sscan 或 zscan 没有 MATCH
.
Instead of scanning do indexing. Create a set or sorted set where you'll store all elements that matches these patterns, and just perform a a sscan or zscan with no MATCH
.
继续做你已经做过的事情.
Keep doing it as you've done already.