如何用PHP和Redis实现排名列表?
作者:BrightSoul
时间:2023-04-24
浏览:0
Redis Assistant
Redis Assistant 是一款为Redis设计的高效可视化管理与监控工具,提供多种操作模式,高效处理服务器数据。日常使用里的持续防护和信息管理会更突出,适合把安全控制放进长期使用流程中的场景。
¥19
Windows/macOS/Linux
2026-08-22
通过php和redis实现一个小功能排行榜,用的数据类型是有序集合:zrevrange递增排序,zrange递减排序/***排行榜*/publicfunctionrank(){//$this->zrem($this->cachekey);$this->redis->del($this->cachekey);$dataOne=[];for($i=0;$iget_random(6,'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ');$
本文目录
通过php和redis实现一个小功能排行榜,用的数据类型是有序集合:zrevrange 递增排序,zrange 递减排序
/**
* 排行榜 */public function rank()
{// $this->zrem($this->cachekey);$this->redis->del($this->cachekey);$dataOne = [];for ($i=0; $i < 5; $i++) {
// 生成随机数$num = rand(0,100);// 生成随机字符串$str = $this->get_random(6,'abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ'); $this->redis->zadd($this->cachekey,$num,json_encode(['name'=>$str]));// 由大到小排序$dataOne = $this->redis->ZREVRANGE($this->cachekey, 0, -1, true);// 由小到大排序$dataTow = $this->redis->ZRANGE($this->cachekey, 0, -1, true);
}echo "";print_r($dataOne);print_r($dataTow);
}// 生成随机字符串public function get_random($len,$chars)
{$hash = "";$max = strlen($chars) - 1;for ($i=0; $i < $len; $i++) { $hash .= $chars[mt_rand(0,$max)];
}return $hash;
}
作者最新文章
SkildArt官网 SkildArtAI电商视觉创作基础设置
2026-11-24 12:23
钉钉文档怎么生成分享二维码和长图
2026-11-24 10:31
漫蛙漫画官网地址永久有效收藏
2026-11-23 13:24
AO3如何关注作者及更新方法
2026-11-23 11:46
AO3中文版官网与使用指南
2026-11-19 14:13
上一篇:
java怎么一次生成多个随机数出来
热门文章
更多
精品专题
更多
Mac软件
更多
WINDOWS
更多

































