$redis->zAdd("tq:ranks:recent:{$type}:{$today}", $score, $id); } } } foreach ($types as $type => $value) { $multi = $redis->multi(); $multi->del("tq:ranks:recent:{$type}"); $multi->zUnion("tq:ranks:recent:{$type}", ["tq:ranks:recent:{$type}:{$today}"]); $multi->expire("tq:ranks:recent:{$type}", 100000); $multi->expire("tq:ranks:recent:{$type}:{$today}", 7 * 86400); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:shipsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:shipsLost"); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:iskDestroyed"); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:iskLost"); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:pointsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:recent:{$type}:{$today}:pointsLost"); $multi->exec(); } $redis->setex($todaysKey, 87000, true); Util::out("Recent rankings complete"); function zAdd(&$multi, $key, $value, $id) { $value = max(1, (int) $value); $multi->zAdd($key, $value, $id); $multi->expire($key, 100000); } function moveAndExpire(&$multi, $today, $key) { $newKey = str_replace(":{$today}", "", $key); $multi->rename($key, $newKey); $multi->expire($newKey, 100000);
$score = ceil($avg / $adjuster); $redis->zAdd("tq:ranks:alltime:{$type}:{$today}", $score, $id); } } } foreach ($types as $type => $value) { $multi = $redis->multi(); $multi->zUnion("tq:ranks:alltime:{$type}", ["tq:ranks:alltime:{$type}:{$today}"]); $multi->expire("tq:ranks:alltime:{$type}", 100000); $multi->expire("tq:ranks:alltime:{$type}:{$today}", 7 * 86400); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:shipsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:shipsLost"); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:iskDestroyed"); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:iskLost"); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:pointsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:alltime:{$type}:{$today}:pointsLost"); $multi->exec(); } $redis->setex($todaysKey, 87000, true); Util::out("Alltime rankings complete"); function zAdd(&$multi, $key, $value, $id) { $value = max(1, (int) $value); $multi->zAdd($key, $value, $id); $multi->expire($key, 100000); } function moveAndExpire(&$multi, $today, $key) { $newKey = str_replace(":{$today}", "", $key); $multi->rename($key, $newKey); $multi->expire($newKey, 100000);
$redis->zAdd("tq:ranks:weekly:{$type}:{$today}", $score, $id); } } } foreach ($types as $type => $value) { $multi = $redis->multi(); $multi->del("tq:ranks:weekly:{$type}"); $multi->zUnion("tq:ranks:weekly:{$type}", ["tq:ranks:weekly:{$type}:{$today}"]); $multi->expire("tq:ranks:weekly:{$type}", 100000); $multi->expire("tq:ranks:weekly:{$type}:{$today}", 7 * 86400); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:shipsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:shipsLost"); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:iskDestroyed"); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:iskLost"); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:pointsDestroyed"); moveAndExpire($multi, $today, "tq:ranks:weekly:{$type}:{$today}:pointsLost"); $multi->exec(); } function moveAndExpire(&$multi, $today, $key) { $newKey = str_replace(":{$today}", "", $key); $multi->rename($key, $newKey); $multi->expire($newKey, 3600); } $redis->setex($todaysKey, 9000, true); Util::out("Weekly rankings complete"); function zAdd(&$multi, $key, $value, $id) { $value = max(1, (int) $value); $multi->zAdd($key, $value, $id); $multi->expire($key, 9000);