一个千万级排行榜怎么实现,每个用户都有自己得名次,同时展示前100名
user_score表
create table user_score
(
id int auto_increment
primary key,
score int default 0 not null,
user_id int default 12 not null,
constraint user_score_id_uindex
unique (id)
);
方案1:冷热数据+redis有序集合
方案2:指定一个冷时间段,处理排名,前一百单存一个redis key,然后各自用户各自存一个redis key,用sh或php命令处理,不会中断(key value存json,外面用脚本跳表去排序)
跳表实现:http://www.xiaomlove.com/2020/03/19/skip-list-implement-by-php/
方案3:sql
select *
from (select row_number() over (order by total desc) as number, user_id, total
from (SELECT SUM(score) AS total,
user_id
FROM user_score
GROUP BY user_id
) t) s
where number <= 3;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
2020-03-03 swoole(3)网络服务模型(单进程阻塞、预派生子进程、单进程阻塞复用模型)
2020-03-03 swoole(2)swoole进程结构