Redis as main DB - use case question RE sets

72 views
Skip to first unread message

Running Turtle

unread,
Nov 6, 2012, 2:48:28 AM11/6/12
to redi...@googlegroups.com
Hello, I'm currently building a web app using Redis as the main database with data passed to client in JSON format.

The webapp has a social component and users can follow other users.

I want to build a profile page with a very basic functionality where a user is able to see a list of say, 20 followers, with a button ("see more") which will display another 20 followers (different from the first 20) each time it is pressed.

Using SETS to store followers ids (user:[userId]:followerIds), I wasn't able to come up with a trivial implementation of the functionality.  So far, because I want to keep followerIds in SETS in order to be able to use commands like SMEMBERS, the "less ugly" solution I can think of is to have a LIST of follower ids in addition to the SET, and then use LRANGE to "paginate" through the followerIds.  This should work, but isn't a very satisfying solution.

If anybody was faced with the same problem or has any pointer to a more elegant solution, I'd be eager to read it.

Thanks

Tim Lossen

unread,
Nov 6, 2012, 8:05:55 AM11/6/12
to redi...@googlegroups.com
you could use a sorted set instead, and insert each follower id with a random score -- then you can paginate with ZRANGE through the set.

tim
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/IpZ7F126kecJ.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

--
http://tim.lossen.de



Running Turtle

unread,
Nov 6, 2012, 9:16:33 AM11/6/12
to redi...@googlegroups.com
That seems to works great.

Thanks for the pointer Tim.

Josiah Carlson

unread,
Nov 6, 2012, 12:05:39 PM11/6/12
to redi...@googlegroups.com
SRANDMEMBER can take an argument of the number of items to return,
with or without duplication. Though that functionality is new in Redis
2.6 .

Regards,
- Josiah
> https://groups.google.com/d/msg/redis-db/-/HchvljGFpE4J.
Reply all
Reply to author
Forward
0 new messages