コード例 #1
0
        public static async Task <UserApiAuthKey> GetApiAuthKey(string apiKey)
        {
            var existing = await _rediscache.GetValueAsync(apiKey);

            if (existing != null)
            {
                return(existing);
            }

            using (var context = new ApplicationDbContext())
            {
                existing = await context.Users
                           .Where(x => x.ApiKey == apiKey)
                           .Select(x => new UserApiAuthKey
                {
                    UserId    = x.Id,
                    Key       = x.ApiKey,
                    Secret    = x.ApiSecret,
                    IsEnabled = !x.IsDisabled && x.IsApiEnabled
                }).FirstOrDefaultNoLockAsync();
            }

            if (existing != null)
            {
                await _rediscache.AddAsync(apiKey, existing);
            }

            return(existing);
        }
コード例 #2
0
 private async Task <ChatUser> GetUserFromCache(string userId)
 {
     return(await _onlineUsers.GetValueAsync(userId));
 }