You can use set operations and store intermediate values, for example:
SUNIONSTORE temp S1 S2
SDIFF temp S3
Then you can delete the `temp` key. If that works for you, an
optimization would be to wrap those commands in a MULTI/EXEC block:
MULTI
SUNIONSTORE temp S1 S2
SDIFF temp S3
DEL temp
EXEC
At some point I had to do something similar but without knowing in
advance the operations I needed to perform. I wrote a Lua script
called Stal (
https://github.com/soveran/stal) that receives an
s-expression in the form of a JSON array and returns the result. For
example, let's say you want to express the above operation as an
s-expression:
(SDIFF (SUNION S1 S2) S3)
Translated to a JSON array, it would be like this:
["SDIFF", ["SUNION", "S1", "S2"], "S3"]
And that's what you can ask Stal to solve:
$ redis-cli --eval stal.lua , '["SDIFF", ["SUNION", "S1", "S2"], "S3"]'
Stal will take care of creating and removing any temporary keys.
There are two wrappers available, one for Ruby and one for Crystal,
that allow you interact with Stal. Writing a wrapper for Python should
be trivial if you think this solves your problem.
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
redis-db+u...@googlegroups.com.
> To post to this group, send email to
redi...@googlegroups.com.
> Visit this group at
https://groups.google.com/group/redis-db.
> For more options, visit
https://groups.google.com/d/optout.