当前位置:网站首页>Redis ranking
Redis ranking
2022-07-21 08:08:00 【Chenqing Nuo language】
redis Ordered set of zset Be similar to Java Of SoretedSet and HashMap The combination of , On the one hand, it is a set, Can guarantee internal value Uniqueness , On the other hand, it can give each value Give one score, On behalf of the score Sort weight for .
zset It can be used to store students' grades ,value Value is student's ID,score It's the student's examination result , Students' nouns can be obtained by ranking their scores . It can also be used to store fan lists ,value Users who are fans ID,score It's about time , You can sort the fan list according to the time of interest .
public function rankingList()
{
// Connect redis
$redis = new Redis();
$redis->connect('127.0.0.1', '6379');
// Query data
$data = Money::select()->toArray();
// dd($data);
// Array processing Cumulative Commission
// $newArr = array();
// foreach ($data as $v)
// {
// if (array_key_exists($v['tid'],$newArr))
// {
// $newArr[$v['tid']]['money'] += $v['money'];
// }
// else {
// $newArr[$v['tid']] = $v;
// }
// }
// dd($newArr);
// Add to redis Ordered set
foreach ($data as $v)
{
$redis->zincrby('tag1',$v['money'],$v['tid']);
}
$data = $redis->zrevrange('tag1', 0, -1);
$ids = implode(',', $data);
// $score = $redis->zRevRange('tag1', 0, -1, true);
// Judge data time ranking
if(!empty($time))
{
$data = Money::whereTime('add_time',$time)->whereIn('tid', $ids)->order(Db::raw("FIELD(tid,$ids)"))->select()->toArray();
}else{
$data = Money::whereIn('tid', $ids)->order(Db::raw("FIELD(tid,$ids)"))->select()->toArray();
}
dd($data);
}
边栏推荐
- uva11100
- Chuqi technology is committed to design and development
- 租用香港服务器您需要知道的5件事
- PX4模块设计之十:PX4启动过程
- The drawing principle and application of Bao Jiao Bao Hui Bezier curve
- 上海文旅局局长:安全是文旅业的生命线,正抢抓元宇宙新赛道
- 2022/7/17
- Audio and video learning (IX) -- RTCP protocol
- 解决Visual Studio 2019 更新升级后,出现更新实体数据模型失败现象
- Uva11627 (website cannot be accessed, not submitted)
猜你喜欢
超实用转型攻略!《2022央国企云原生落地实用指南》重磅发布(附下载链接)
openGauss内核分析:查询重写
kubernetes创建一个dashboard只读权限的用户(具有exec权限)
LeetCode - 回文数
Avec la sortie de HongMeng 3.0, la fusion Multi - écrans a progressé régulièrement, mais Google a subi une nouvelle chute
Disjoint Set class (union search set)
面試真題2
史上最全的mysql数据类型汇总(下)
[web vulnerability exploration] external entity injection vulnerability
动态库和静态库(.so/dll,.a/lib)
随机推荐
从0到1 拿下C语言—程序结构及使用示例
Uva11627 (website cannot be accessed, not submitted)
2020 Huawei cloud community annual technology collection, 700 pages + free download| Yunxiang library No.01 recommendation (with free download)
Ultra light fast generic face detector 1MB custom dataset training | multi classification modification Guide (1)
路演会上会登记结论的委员信息页面
PX4模块设计之十:PX4启动过程
What is the difference between dall-e2 and imgen? Reddit hot post inventory effect difference
租用香港服务器您需要知道的5件事
LeetCode - 回文数
OCR/STR生僻字数据训练 | PaddleOCR的Fine-tune常见问题汇总(3)
Audio and video learning (VIII) -- RTP protocol
Redis Learning notes (1) - Power Node of Station B
ovirt:api接口+keystone接口+neutron接口示例
多线程冲突的解决——锁
G025-DB-GS-INS-02 OpenEuler 部署 OpenGauss(1主1备)
sql 命令insert into 的作业没办法通过savepoint启动么?或是我集群关闭重启的时
第2讲 Hi3861的WiFi实验-API-4
没错,又是一位月薪过万的测试小伙伴!
开源demo| ARCall 小程序开源示例发布
kubernetes创建一个dashboard只读权限的用户(具有exec权限)