开发者

Compute the difference between two sets (sorted and simple)

开发者 https://www.devze.com 2023-02-25 00:07 出处:网络
Is there a way to compute the difference between two sorted sets (zset) or do I have to use simple sets for this?

Is there a way to compute the difference between two sorted sets (zset) or do I have to use simple sets for this?

Problem:

  1. Set F contains a list of sorted 开发者_Go百科id's (sorted set, full list)
  2. Set K contains a list of id's (simple set, subset of F)

I want to retrieve every entry in F, in order, that's not in K.

Is this possible using Redis alone or do I have to do the computation on the application? If yes, what is the best way?

EDIT: SDIFF does not suit this purpose as it doesn't allow sorted sets.


Make a copy of F as a simple set. Let's call it G. Now perform the SDIFF.

Or...

Make a copy of F as a sorted set. Let's call it G. Iterate through K and remove each element from G.

SDIFF really should work on sorted sets, regular sets, or combinations. But, at this time, it does not.

Also, if F is very large, you may see some performance hits when you make a copy of it. In this case, create a set G in your Redis DB that it updated when K is updated. That is, F and G are initially equal. As you add elements to K, remove the element from G.

0

精彩评论

暂无评论...
验证码 换一张
取 消