1.增加互斥锁:保证缓存和数据库数据一致性
2.增加消费队列,保证mysql数据的正常保存
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\library\game\StreakWinReward;
|
||||
use app\common\service\GameHotDataRedis;
|
||||
use app\common\service\GameHotDataCoordinator;
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ class GameConfig extends Model
|
||||
{
|
||||
$key = trim((string) ($model->getAttr('config_key') ?? ''));
|
||||
if ($key !== '') {
|
||||
GameHotDataRedis::gameConfigForget($key);
|
||||
GameHotDataCoordinator::afterGameConfigKeyCommitted($key);
|
||||
}
|
||||
if ($key === StreakWinReward::CONFIG_KEY) {
|
||||
StreakWinReward::clearCache();
|
||||
@@ -35,7 +35,7 @@ class GameConfig extends Model
|
||||
{
|
||||
$key = trim((string) ($model->getAttr('config_key') ?? ''));
|
||||
if ($key !== '') {
|
||||
GameHotDataRedis::gameConfigForget($key);
|
||||
GameHotDataCoordinator::afterGameConfigKeyCommitted($key);
|
||||
}
|
||||
if ($key === StreakWinReward::CONFIG_KEY) {
|
||||
StreakWinReward::clearCache();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\service\GameHotDataRedis;
|
||||
use app\common\service\GameHotDataCoordinator;
|
||||
use support\think\Model;
|
||||
|
||||
class GameRecord extends Model
|
||||
@@ -46,12 +46,12 @@ class GameRecord extends Model
|
||||
public static function onAfterWrite(GameRecord $model): void
|
||||
{
|
||||
$id = filter_var($model->getAttr('id'), FILTER_VALIDATE_INT);
|
||||
GameHotDataRedis::gameRecordForget($id === false ? null : $id);
|
||||
GameHotDataCoordinator::afterGameRecordCommitted($id === false ? null : $id);
|
||||
}
|
||||
|
||||
public static function onAfterDelete(GameRecord $model): void
|
||||
{
|
||||
$id = filter_var($model->getAttr('id'), FILTER_VALIDATE_INT);
|
||||
GameHotDataRedis::gameRecordForget($id === false ? null : $id);
|
||||
GameHotDataCoordinator::afterGameRecordCommitted($id === false ? null : $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\service\GameHotDataRedis;
|
||||
use app\common\service\GameHotDataCoordinator;
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
@@ -68,7 +68,7 @@ class User extends Model
|
||||
{
|
||||
$id = filter_var($model->getAttr('id'), FILTER_VALIDATE_INT);
|
||||
if ($id !== false && $id > 0) {
|
||||
GameHotDataRedis::userForget($id);
|
||||
GameHotDataCoordinator::afterUserCommitted($id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class User extends Model
|
||||
{
|
||||
$id = filter_var($model->getAttr('id'), FILTER_VALIDATE_INT);
|
||||
if ($id !== false && $id > 0) {
|
||||
GameHotDataRedis::userForget($id);
|
||||
GameHotDataCoordinator::afterUserCommitted($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user