Files
webman-buildadmin/config/game_hot_cache.php
zhenhui 1eed3cf0f7 1.增加互斥锁:保证缓存和数据库数据一致性
2.增加消费队列,保证mysql数据的正常保存
2026-04-20 14:13:48 +08:00

41 lines
1.8 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
/**
* 游戏侧热点数据 Redis 缓存(用户 / game_config / game_record
*
* 环境变量见 .env-example 中 GAME_HOT_CACHE_*
*/
$envInt = static function (string $key, int $default): int {
$raw = env($key, null);
if ($raw === null || $raw === '') {
return $default;
}
$n = filter_var($raw, FILTER_VALIDATE_INT);
return ($n === false || $n < 1) ? $default : $n;
};
return [
'enabled' => filter_var(env('GAME_HOT_CACHE_ENABLED', true), FILTER_VALIDATE_BOOLEAN),
/** game_config 行缓存(秒),后台修改会主动删除 */
'ttl_game_config' => $envInt('GAME_HOT_CACHE_TTL_GAME_CONFIG', 86400),
/** game_record 行缓存(秒) */
'ttl_game_record' => $envInt('GAME_HOT_CACHE_TTL_GAME_RECORD', 60),
/** user 行缓存(秒),余额/连胜变更会主动删除 */
'ttl_user' => $envInt('GAME_HOT_CACHE_TTL_USER', 90),
/** 后台对同一用户互斥操作(如钱包加减点)的 Redis 锁 TTL */
'admin_user_mutation_lock_ttl' => $envInt('GAME_HOT_CACHE_ADMIN_USER_LOCK_TTL', 30),
/** 是否启用缓存回源队列(独立进程消费) */
'enable_cache_write_queue' => filter_var(env('GAME_HOT_CACHE_ENABLE_WRITE_QUEUE', true), FILTER_VALIDATE_BOOLEAN),
/** 队列 Redis List 键名 */
'queue_list_key' => env('GAME_HOT_CACHE_QUEUE_LIST_KEY', 'dfw:q:hot_data_write'),
/** 队列最大长度,超出则丢弃最旧一条再入队 */
'queue_max_length' => $envInt('GAME_HOT_CACHE_QUEUE_MAX_LENGTH', 50000),
/** 消费者 Timer 间隔(秒) */
'queue_consumer_tick_seconds' => (float) (env('GAME_HOT_CACHE_QUEUE_CONSUMER_TICK', '0.1')),
/** 每轮最多处理任务数 */
'queue_consumer_batch' => $envInt('GAME_HOT_CACHE_QUEUE_CONSUMER_BATCH', 80),
];