Reputation: 1199
I am using redis to store a list of items in a set. I add a very similar list to the set periodically, and obviously, the sorted set only adds new items if they don't already exist. Is there a way to get that list of new items that were just added? The ones that didn't already exist in the set?
Danke schoen.
Upvotes: 1
Views: 474
Reputation: 15773
In addition to iterating over your new list as described by Sergio, you could store the keys from your sorted set in a set, store your new list in a set and do an sdiff or sdiffstore on them to get the difference.
Which route will be better is a judgement call for you based in your code and data set. If the new list is short if probably go with simple iteration using the zadd command like Sergio describes. Otherwise I'd test to see which is better for my use case.
Upvotes: 1
Reputation: 230286
ZADD
command, if called with one score/member pair, returns 1 if member was new and 0 if it already existed. You can use this. Add elements one by one and check return values.
Upvotes: 3