Random subset of followers/following
HugoMag opened this issue · comments
Hi,
I'm using redback to save a SocialGraph (like twitter) and its working great.
Thanks for creating this project. Its been a great help!
One thing that I think its missing is a way to get only a random subset of followers and/or following.
This is one of twitter functionalities: It shows in the right panel (next to the timeline) a subset of 5 followers and 5 following.
From what I gathered this cannot be done using sets in redis, because you can only get one random element each time (using the SRANDMEMBER command), so that leaves doing this on the client side, and getting for instance 5 random elements from a 1000 array in javascript is not the best way to go.
Do you know another way to do this?
I've already asked in the redis google groups if there are other ways to do this.
http://groups.google.com/group/redis-db/browse_thread/thread/a58699d22de43456
Thanks for your help.
Best regards,
Hugo
P.S: Sorry for adding this as an issue, but I didn't found a better place to ask this question.
Hey, interesting problem. You've only really got two options, a) call SRANDMEMBER repeatedly (as suggested in GG), or b) roll your own lua script using the new lua scripting feature.
Although it's outside the scope of the library, I'd personally go with option B. You can see some examples here on how to get started.
Good luck!
Hi,
Thanks for your help.
I've created a redback branch with getRandomFollowing() and getRandomFollowers(). Maybe you can push it to the master branch for the next release.
Please check http://groups.google.com/group/redis-db/browse_thread/thread/a58699d22de43456 for the reasoning behind it.
Thanks again.
Best regards,
Hugo