$redis = new Redis(); $redis->connect('127.0.0.1', '6379'); $scoreKey = 'user:score'; // init rank $uidList = range(10000, 20000); // 初始化列表 shuffle($uidList); foreach ($uidList as $uid) { $score = mt_rand(1, 10000000); $redis->zAdd($scoreKey, $score, $uid); } $scoreKey = 'user:score'; // get top 50 // zrange user:score -50 -1 withscores $top50List = $redis->zRange($scoreKey, -50, -1, TRUE); $top50List1 = $redis->zRevRange($scoreKey, 0, 50, TRUE); // 删除一个key $redis->zRem($scoreKey,13295); echo '<pre/>'; print_r($top50List); print_r($top50List1);
redis 基本redis有序集合生成游戏排行榜数据
最新推荐文章于 2024-04-27 17:01:58 发布