2使用Redis跟踪在线用户的方法。哪一个更快? [英] 2 approaches for tracking online users with Redis. Which one is faster?

查看:191
本文介绍了2使用Redis跟踪在线用户的方法。哪一个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我发现了一个漂亮的博客文章,提供了两种方法,在Redis的帮助下跟踪网站的在线用户。



1)智能键和设置expiration
http://techno-weenie.net/2010/2/3/where-s-waldo-track-user-locations-with-node-js-and-redis



2)设置和相交
http://www.lukemelia.com/blog/archives/2010/01/17/redis-in-practice-whos-online/



你可以判断哪一个应该更快,为什么?

解决方案

要知道特定用户是否在线,第一种方法会快很多 - 没有比读取单个键快的速度。



在特定页面上查找用户不清楚(我还没有看到关于交叉或通配符键的性能的硬数字),但是如果集合大到足以在任一实现中引起性能问题,则不显示它们是不切实际的。 p>

对于将用户匹配到朋友列表,我可能会使用第一种方法 - 即使是几百个获取操作(检查列表中每个人的状态)应该优于交集如果这些集合具有大量的记录并且难以维护,则多个集合。



Redis集合更适合于无法用键完成的事情,获取集合中的所有项目比检查特定项目是否在集合中更重要。


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?

解决方案

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.

这篇关于2使用Redis跟踪在线用户的方法。哪一个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆