I’m using sorted sets in the following way.
I have a normal set called ‘available:numbers’ which contains phone numbers. Now say a user signs up, so we have a user id called ‘uid’. This new user is alloted a number from the ‘available:numbers’ set. I have a user hash where I could store this user->alloted_number mapping. The problem is how to store multiple numbers associated with the same user?
I’m wondering if it’s possible to use a sorted set here? I could POP a number from ‘available:numbers’ and add it to a sorted set called ‘used:numbers’ with the score that is the ‘uid’ of the user. Since score does not need to be unique and all members are unique, this seems a perfect fit. What I want to know is that is it possible to get all members of a sorted set given a score? This way I could yank out all numbers belonging to a particular ‘uid’ Or should I just forget about sorted set for this purpose
Thanks
May I suggest that you keep a set for each user instead? So:
It seems more manageable, to me. That being said, you can indeed get all members of a sorted set by score, see ZRANGEBYSCORE:
I suggest you read through the documentation on all available commands in redis, the documentation is really top notch – and you can try out (most) commands live – really awesome.