views:

206

answers:

1

Recently I found an nice blog post presenting 2 approaches for tracking online users of a web site with the help of Redis.

1) Smart-keys and setting their expiration http://techno-weenie.net/2010/2/3/where-s-waldo-track-user-locations-with-node-js-and-redis

2) Set-s and intersects http://www.lukemelia.com/blog/archives/2010/01/17/redis-in-practice-whos-online/

Can you judge which one should be faster and why?

+1  A: 

For knowing whether or not a particular user is online, the first method will be a lot faster - nothing is faster than reading a single key.

Finding users on a particular page is not as clear (I haven't seen hard numbers on the performance of either intersection or wildcard keys), but if the set is big enough to cause performance problems in either implementation it isn't practical to display them all anyway.

For matching users to a friends list I would probably go with the first approach also - even a few hundred get operations (checking the status of everyone in the list) should outperform intersection on multiple sets if those sets have a large number of records and are difficult to maintain.

Redis sets are more appropriate for things that can't be done with keys, particularly where getting all items in the set is more important than checking if a particular item is in the set.

Tom Clarkson
Unless your redis library is pipelined, a few hundred GET operations could be very slow simply due to network latency.
rpetrich