From 0ad2d64ca1e093aacd3c7963734302bb389343aa Mon Sep 17 00:00:00 2001 From: Rhilip Date: Sat, 16 Mar 2019 13:44:36 +0800 Subject: [PATCH] fix(UserTrackerStatus): Fix redis cache key miss --- framework/User/UserTrait.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/framework/User/UserTrait.php b/framework/User/UserTrait.php index 3efa4c7..791366e 100644 --- a/framework/User/UserTrait.php +++ b/framework/User/UserTrait.php @@ -268,24 +268,26 @@ public function getTimeRatio() public function getActiveSeed() { - $active_seed = app()->redis->hGet($this->infoCacheKey, 'active_seed_count'); + $active_seed = app()->redis->hGet('User:' . $this->id . ':peer_count', 'active_seed_count'); if ($active_seed === false) { $active_seed = app()->pdo->createCommand("SELECT COUNT(id) FROM `peers` WHERE `user_id` = :uid AND `seeder`='yes'")->bindParams([ 'uid' => $this->id ])->queryScalar() ?: 0; - app()->redis->hSet($this->infoCacheKey, 'active_seed_count', $active_seed); + app()->redis->hSet('User:' . $this->id . ':peer_count', 'active_seed_count', $active_seed); + app()->redis->expire('User:' . $this->id . ':peer_count',60); } return $active_seed; } public function getActiveLeech() { - $active_leech = app()->redis->hGet($this->infoCacheKey, 'active_leech_count'); + $active_leech = app()->redis->hGet('User:' . $this->id . ':peer_count', 'active_leech_count'); if ($active_leech === false) { $active_leech = app()->pdo->createCommand("SELECT COUNT(id) FROM `peers` WHERE `user_id` = :uid AND `seeder`='no'")->bindParams([ 'uid' => $this->id ])->queryScalar() ?: 0; - app()->redis->hSet($this->infoCacheKey, 'active_leech_count', $active_leech); + app()->redis->hSet('User:' . $this->id . ':peer_count', 'active_leech_count', $active_leech); + app()->redis->expire('User:' . $this->id . ':peer_count',60); } return $active_leech; }