public async Task <BodyResponse <LevelInfo> > Handle(GetLevelInfoCommand request, CancellationToken cancellationToken) { //读取redis account信息 LevelInfo levelinfo = await _redis.GetLevelInfo(request.Id); if (levelinfo == null) { //从数据库中获取 using (var loker = _redis.Locker(KeyGenHelper .GenUserKey(request.Id, LevelInfo.ClassName))) { loker.Lock(); levelinfo = await _levelRepository.FindAndAdd(request.Id, new LevelInfo(request.Id, 1, 0, _levelManager.GetNeedExp(1))); _ = _redis.SetLevelInfo(levelinfo); } } BodyResponse <LevelInfo> response = new BodyResponse <LevelInfo>(StatusCodeDefines.Success, null, levelinfo); return(response); }
public async Task Handle(FinishRegisterRewardEvent notification, CancellationToken cancellationToken) { using (var loker = _redis.Locker(KeyGenHelper.GenUserKey(notification.Id, AccountInfo.className))) { loker.Lock(); AccountInfo info = await _redis.GetAccountInfo(notification.Id); if (info == null) { info = await _accountRepository.GetByIdAsync(notification.Id); } info.Flags |= GetAccountBaseInfoMqResponse.SomeFlags.RegisterReward; await Task.WhenAll(_accountRepository.UpdateAsync(info), _redis.SetAccountInfo(info)); } }
public async Task<BodyResponse<GameInfo>> Handle(GetGameInfoCommand request, CancellationToken cancellationToken) { GameInfo gameinfo = await _redis.GetGameInfo(request.Id); if (gameinfo == null) { using (var loker = _redis.Locker(KeyGenHelper .GenUserKey(request.Id, GameInfo.ClassName))) { loker.Lock(); gameinfo = await _gameRepository.FindAndAdd(request.Id, new GameInfo(request.Id, 0, 0, 0)); _ = _redis.SetGameInfo(gameinfo); } } BodyResponse<GameInfo> response = new BodyResponse<GameInfo>(StatusCodeDefines.Success, null, gameinfo); return response; }