コード例 #1
0
        public async Task GameUserLoginAsync(string gameAppId, string gameUserId, DateTimeOffset?dateTime)
        {
            int[] timePrecisions = new int[] { 3600, 3600 * 24 };
            // 查找用户是否存在
            if (!await GameUserExistsAsync(gameAppId, gameUserId))
            {
                // 添加新用户
                string sequentialKey        = RedisKeys.Concat(gameAppId, RedisKeys.UserSequentialId);
                var    gameUserSequentialId = await redisProvider.GetGameUserSequentialIdAsync(sequentialKey);

                await AddGameUserSetAsync(gameAppId, gameUserId).ConfigureAwait(false);
                await AddGameUserHashAsync(gameAppId, gameUserId, gameUserSequentialId).ConfigureAwait(false);

                // 统计新增用户
                string newUserKey = RedisKeys.Concat(gameAppId, RedisKeys.NewGameUserCount);
                foreach (var precision in timePrecisions)
                {
                    await redisProvider.UpdateCounterAsync(newUserKey, precision).ConfigureAwait(false);

                    await redisProvider.UpdateCounterPrecisionAsync(newUserKey, precision).ConfigureAwait(false);
                }
            }
            // 统计用户登录
            string loginKey = RedisKeys.Concat(gameAppId, RedisKeys.GameUserLoginCount);

            foreach (var precision in timePrecisions)
            {
                await redisProvider.UpdateCounterAsync(loginKey, precision).ConfigureAwait(false);

                await redisProvider.UpdateCounterPrecisionAsync(loginKey, precision).ConfigureAwait(false);
            }

            // 统计用户活跃
            await GameUserActiveAsync(gameAppId, gameUserId, dateTime).ConfigureAwait(false);
        }
コード例 #2
0
        public async Task <IActionResult> LoginAsync([FromBody] GameUserDto gameUserDto)
        {
            //// 验证 App是否存在
            //if (!await gameAppService.GameAppExistsAsync(gameUserDto.GameAppId))
            //{
            //    return BadRequest("app does not exist.");
            //}
            //// 添加用户登录统计
            //await gameStatsService.GameUserLoginAsync(gameUserDto.GameAppId, gameUserDto.OpenId, DateTimeOffset.Now);

            await redisProvider.GetGameUserSequentialIdAsync("TestIds").ConfigureAwait(false);

            return(Ok());
        }