且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

设计问题:如何显示在线用户数?

更新时间:2023-12-02 13:38:10

将涉及到一个数据库.因此,每次有人登录该站点时,您都​​可以在用户表中为 last_login 设置一个字段.然后可以有一个脚本对该用户的表进行查询,以计算最后 x 时间内 last_login 的行数.***缓存它并每隔 z 时间重新填充这个缓存,然后从这个缓存中提取,而不是每次请求对用户的表运行查询.所以数据库+某种缓存系统.

A database will be involved. So every time someone logs into the site, you can have a field in a user's table for last_login. And then there can be a script that does a query against this user's table to count the number of rows last_login within the last x amount of time. It may be good to cache this and repopulate this cache every z amount of time, and then pull from this cache as oppose to running a query against the user's table every request. So database + some kind of caching system.