Skip to content

Commit

Permalink
perf: 修改流量统计Service使用默认缓存器,而不是指定的redis
Browse files Browse the repository at this point in the history
  • Loading branch information
gua committed Nov 14, 2023
1 parent 18ad8a9 commit ee47d11
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/Services/StatisticalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public function setEndAt($timestamp) {
}

public function setServerStats() {
$this->serverStats = Cache::store('redis')->get("stat_server_{$this->startAt}");
$this->serverStats = Cache::get("stat_server_{$this->startAt}");
$this->serverStats = json_decode($this->serverStats, true) ?? [];
if (!is_array($this->serverStats)) {
$this->serverStats = [];
}
}

public function setUserStats() {
$this->userStats = Cache::store('redis')->get("stat_user_{$this->startAt}");
$this->userStats = Cache::get("stat_user_{$this->startAt}");
$this->userStats = json_decode($this->userStats, true) ?? [];
if (!is_array($this->userStats)) {
$this->userStats = [];
Expand Down Expand Up @@ -95,7 +95,7 @@ public function statServer($serverId, $serverType, $u, $d)
} else {
$this->serverStats[$serverType][$serverId] = [$u, $d];
}
Cache::store('redis')->set("stat_server_{$this->startAt}", json_encode($this->serverStats));
Cache::set("stat_server_{$this->startAt}", json_encode($this->serverStats));
}

public function statUser($rate, $userId, $u, $d)
Expand All @@ -107,7 +107,7 @@ public function statUser($rate, $userId, $u, $d)
} else {
$this->userStats[$rate][$userId] = [$u, $d];
}
Cache::store('redis')->set("stat_user_{$this->startAt}", json_encode($this->userStats));
Cache::set("stat_user_{$this->startAt}", json_encode($this->userStats));
}

public function getStatUserByUserID($userId): array
Expand Down Expand Up @@ -165,12 +165,12 @@ public function getStatServer()

public function clearStatUser()
{
Cache::store('redis')->forget("stat_user_{$this->startAt}");
Cache::forget("stat_user_{$this->startAt}");
}

public function clearStatServer()
{
Cache::store('redis')->forget("stat_server_{$this->startAt}");
Cache::forget("stat_server_{$this->startAt}");
}

public function getStatRecord($type)
Expand Down

0 comments on commit ee47d11

Please sign in to comment.