1.优化game_config
2.备份MySQL数据库
This commit is contained in:
@@ -25,6 +25,15 @@ final class GameHotDataRedis
|
||||
|
||||
private const KEY_USER = 'dfw:v1:user:';
|
||||
|
||||
/**
|
||||
* 进程内实例化缓存(避免同一请求/进程内重复打 Redis/DB)。
|
||||
* - key => null:表示已确认不存在(负缓存)
|
||||
* - key => array:表示已加载行数据
|
||||
*
|
||||
* @var array<string, array<string, mixed>|null>
|
||||
*/
|
||||
private static array $gcLocal = [];
|
||||
|
||||
public static function enabled(): bool
|
||||
{
|
||||
return config('game_hot_cache.enabled', true) === true;
|
||||
@@ -38,23 +47,30 @@ final class GameHotDataRedis
|
||||
if ($configKey === '') {
|
||||
return null;
|
||||
}
|
||||
if (array_key_exists($configKey, self::$gcLocal)) {
|
||||
$cachedLocal = self::$gcLocal[$configKey];
|
||||
return is_array($cachedLocal) ? $cachedLocal : null;
|
||||
}
|
||||
if (self::enabled()) {
|
||||
$cached = self::redisGet(self::KEY_GC . $configKey);
|
||||
if ($cached !== null && $cached !== '') {
|
||||
$decoded = json_decode($cached, true);
|
||||
if (is_array($decoded)) {
|
||||
self::$gcLocal[$configKey] = $decoded;
|
||||
return $decoded;
|
||||
}
|
||||
}
|
||||
}
|
||||
$row = Db::name('game_config')->where('config_key', $configKey)->find();
|
||||
if (!$row) {
|
||||
self::$gcLocal[$configKey] = null;
|
||||
return null;
|
||||
}
|
||||
if (self::enabled()) {
|
||||
$ttl = self::intConfig('ttl_game_config', 86400);
|
||||
self::redisSetEx(self::KEY_GC . $configKey, $ttl, json_encode($row, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
self::$gcLocal[$configKey] = $row;
|
||||
return $row;
|
||||
}
|
||||
|
||||
@@ -64,6 +80,7 @@ final class GameHotDataRedis
|
||||
return;
|
||||
}
|
||||
self::redisDel(self::KEY_GC . $configKey);
|
||||
unset(self::$gcLocal[$configKey]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +98,7 @@ final class GameHotDataRedis
|
||||
}
|
||||
$ttl = self::intConfig('ttl_game_config', 86400);
|
||||
self::redisSetEx(self::KEY_GC . $configKey, $ttl, json_encode($row, JSON_UNESCAPED_UNICODE));
|
||||
self::$gcLocal[$configKey] = $row;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user