iamght
iamght

Reputation: 132

Query data from multi keys sorted sets in redis

I have several sorted sets stored in redis. Like:

ZADD tag:1 1 1 2 2 3 3 4 4 5 5 6 6

ZADD tag:2 21 1 22 2 23 3 24 4 25 5 26 6

ZADD tag:3 31 1 32 2 33 3 34 4 35 5 36 6

Here is my question: I want to get the data sorted by scores in tag:1 and tag:2, or tag:1 and tag:3, or tag:1,tag:2,and tag:3. That means I need to get data from different key combination([ 1 ] [ 2 ] [ 3 ] [ 1,2,3 ] [ 1,2 ] [ 2, 3 ] [ ... ] ). I have hundreds of this kind of sorted sets, with each sorted set that can be combined to any one/two/more of the others.

I kinda not choosing the ZUNIONSTORE, cause all the combination is temporary, and ZUNIONSTORE will create another new sorted set, and this set will have very low possibility for reusing. So is there any good idea to solve my problem, or any new solution to help me? Thanks in advance!

Upvotes: 0

Views: 612

Answers (1)

Itamar Haber
Itamar Haber

Reputation: 49962

Despite your reluctance, use ZUNIONSTORE for this. Once you're done, just DEL the result. This workflow can be embedded in a Lua script that performs the actions and returns the unified result.

Upvotes: 2

Related Questions