Reputation: 31
Is it possible to compute multiset opeartion in redis using pipes i.e to say
(a union b union c) intersect (d union c) SUNION a b c SINTER d c
Upvotes: 2
Views: 879
Reputation: 1781
No, but you can use trancastions (MULTI)
MULTI
SUNIONSTORE abc a b c
SUNIONSTORE cd c d
SINTERSTORE i abc cd
SMEMBERS i
DEL abc cd i
EXEC
p.s But it seems like you dont need to use c becouse after all its members will placed in i
Upvotes: 0
Reputation: 16585
No, because in a pipeline you only get results once the entire set of commands is sent (see documentation), ergo as you probably guessed you need to fetch the result of each nested operation in your example separately.
Something very similar however can be achieved using the scripting capability built in redis 2.6 with some lua, and it sounds like this could fit your bill:
EVAL "return redis.call('sinter', redis.call('sunion', 'a', redis.call('sunion', 'b', 'c')), redis.call('sunion', 'd', 'c'))"
The code above is a simplification and it's untested, but it should give you a rough idea of what's possible. More info on the documentation here.
Upvotes: 3