private static async Task UpdateSubjectRefreshTokensList(string token, RefreshTokenDescription desc, IRedisConnection c)
        {
            var skKey = SubjectRefreshTokensRedisKey.Create(desc.LoginRequest.Subject);
            var sk    = new RedisKey <SubjectRefreshTokenList>(skKey, c);
            var subjectRefreshTokenList = await sk.GetAsync();

            if (subjectRefreshTokenList != null)
            {
                var expiredRt = subjectRefreshTokenList
                                .Where(t => t.NotAfter < DateTime.Now)
                                .ToArray();
                foreach (var srt in expiredRt)
                {
                    subjectRefreshTokenList.Remove(srt);
                }
            }
            else
            {
                subjectRefreshTokenList = new SubjectRefreshTokenList();
            }

            subjectRefreshTokenList.Add(new SubjectRefreshToken
            {
                RefreshToken = token,
                NotAfter     = desc.NotAfter
            });

            await sk.SetAsync(subjectRefreshTokenList);
        }
        public async Task <LoginRequest> Get(string authCode)
        {
            var keyName = LoginRedisKey.Create(authCode);

            using (var c = await _redisManager.GetConnection())
            {
                var requestKey = new RedisKey <LoginRequest>(keyName, c);
                return(await requestKey.GetAsync());
            }
        }
        public async Task <LoginRequest> Get(string token)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            using (var c = await RedisManager.GetConnection())
            {
                var tkKey         = RefreshTokenRedisKey.Create(token);
                var tk            = new RedisKey <RefreshTokenDescription>(tkKey, c);
                var refrTokenDesc = await tk.GetAsync();

                return(refrTokenDesc?.LoginRequest);
            }
        }
        public async Task RemoveBySubject(string subject)
        {
            if (subject == null)
            {
                throw new ArgumentNullException(nameof(subject));
            }

            using (var c = await RedisManager.GetConnection())
            {
                var skKey = SubjectRefreshTokensRedisKey.Create(subject);
                var sk    = new RedisKey <SubjectRefreshTokenList>(skKey, c);
                var subjectRefreshTokenList = await sk.GetAsync();

                if (subjectRefreshTokenList != null)
                {
                    var keysToRemove = subjectRefreshTokenList
                                       .Select(itm => RefreshTokenRedisKey.Create(itm.RefreshToken));
                    await c.DeleteKeysAsync(keysToRemove);
                }

                await sk.DeleteAsync();
            }
        }