Skip to content

Commit 948177f

Browse files
author
v2board
committed
update: stat service
1 parent b39299b commit 948177f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ DB_USERNAME=root
1414
DB_PASSWORD=123456
1515

1616
BROADCAST_DRIVER=log
17-
CACHE_DRIVER=file
17+
CACHE_DRIVER=redis
1818
QUEUE_CONNECTION=redis
1919
SESSION_DRIVER=redis
2020
SESSION_LIFETIME=120

app/Services/StatisticalService.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ public function setEndAt($timestamp) {
3030
}
3131

3232
public function setServerStats() {
33-
$this->serverStats = Cache::get("stat_server_{$this->startAt}");
33+
$this->serverStats = Cache::store('file')->get("stat_server_{$this->startAt}");
3434
$this->serverStats = json_decode($this->serverStats, true) ?? [];
3535
if (!is_array($this->serverStats)) {
3636
$this->serverStats = [];
3737
}
3838
}
3939

4040
public function setUserStats() {
41-
$this->userStats = Cache::get("stat_user_{$this->startAt}");
41+
$this->userStats = Cache::store('file')->get("stat_user_{$this->startAt}");
4242
$this->userStats = json_decode($this->userStats, true) ?? [];
4343
if (!is_array($this->userStats)) {
4444
$this->userStats = [];
@@ -95,7 +95,7 @@ public function statServer($serverId, $serverType, $u, $d)
9595
} else {
9696
$this->serverStats[$serverType][$serverId] = [$u, $d];
9797
}
98-
Cache::set("stat_server_{$this->startAt}", json_encode($this->serverStats));
98+
Cache::store('file')->set("stat_server_{$this->startAt}", json_encode($this->serverStats));
9999
}
100100

101101
public function statUser($rate, $userId, $u, $d)
@@ -107,7 +107,7 @@ public function statUser($rate, $userId, $u, $d)
107107
} else {
108108
$this->userStats[$rate][$userId] = [$u, $d];
109109
}
110-
Cache::set("stat_user_{$this->startAt}", json_encode($this->userStats));
110+
Cache::store('file')->set("stat_user_{$this->startAt}", json_encode($this->userStats));
111111
}
112112

113113
public function getStatUserByUserID($userId): array
@@ -165,12 +165,12 @@ public function getStatServer()
165165

166166
public function clearStatUser()
167167
{
168-
Cache::forget("stat_user_{$this->startAt}");
168+
Cache::store('file')->forget("stat_user_{$this->startAt}");
169169
}
170170

171171
public function clearStatServer()
172172
{
173-
Cache::forget("stat_server_{$this->startAt}");
173+
Cache::store('file')->forget("stat_server_{$this->startAt}");
174174
}
175175

176176
public function getStatRecord($type)

0 commit comments

Comments
 (0)