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 <WrappedResponse <LevelInfo> > Handle(GetLevelInfoCommand request, CancellationToken cancellationToken) { LevelInfo levelinfo = await _redisRepository.GetLevelInfo(request.Id); if (levelinfo == null) { //从数据库中获取 using var loker = _redisRepository.Locker(KeyGenTool.GenUserKey(request.Id, LevelInfo.ClassName)); loker.Lock(); levelinfo = await _levelRepository.FindAndAdd(request.Id, new LevelInfo(request.Id, 1, 0, LevelManager.GetNeedExp(1))); _ = _redisRepository.SetLevelInfo(levelinfo); } WrappedResponse <LevelInfo> response = new WrappedResponse <LevelInfo>(ResponseStatus.Success, null, levelinfo); return(response); }