I’m trying to use Redis sorted set as my secondary index while the actual data is stored on AWS S3.
Let’s say if I want to support a condition like Name!= 'uma'
is there anyway to achieve that using the inbuilt pattern matching?
For example, Let’s i have below as my sorted set key
ZADD mykey 0 uma:7000
ZADD mykey 0 umesh:7001
ZADD mykey 0 mahes:7002
Can I do something like ZSCAN mykey 0 match !uma?
I don’t want to get all data in-memory and apply != in the application layer.
Thanks in advance
2
Answers
You could create a temporary set containing the members you don’t want and then use ZDIFF:
Add some temp values:
And get the difference:
Oh. And be sure to clean up the temp set:
You can use Lua Script + ZSCAN to do the job. The following is a one-liner that achieves the goal.
There’s a similar question for SCAN. I tried to modify the one-liner in that answer, and made a comment. However, the return value for
SCAN
is quite different fromZSCAN
, so I wrote a dedicated answer for it.