代码来源:自己整理编写
说明:删除指定的一个元素,后别的元素的score会依次递减【必须在命令行下运行】
<?php
if (!isset($argc) || empty($argc))
die ('allow run in console only.');
$serverId = getenv('serverId');
if (empty($serverId))
die("need serverId.\n");
$delScore = $argv[1];
if( empty($delScore) ){
die("need rank\n");
}
print "\nStart Refresh the Arena\n";
$config = \lib\Config::get('onlineServer');
if (empty($config)) {
$host = '127.0.0.1';
$port = 6379;
} else {
$host = $config['host'];
$port = $config['port'];
}
$redis = \lib\RedisCache::getInstance($host, $port)->connect()->connHandle();
$redisKey = 'key';
$redis->zRemRangeByScore($redisKey, $delScore, $delScore);
$start = $delScore+1;
$now = $redis->zRangeByScore($redisKey, $start, "+inf", ['withscores' => TRUE]);
foreach ($now as $value => $score) {
$score = $score-1;
$redis->zAdd($redisKey, $score, $value);
}
print "\nRefresh the Arena Success\n";
本文由 陌上花开 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Jul 1, 2016 at 06:34 am