Exemple #1
0
        /// <summary>
        /// 获取登陆jwttoken
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="redisHelper"></param>
        /// <returns></returns>
        public object GetJwtToken(string userName, IRedisHelper redisHelper)
        {
            var token = JwtHelper.GetJwtToken(new Dictionary <string, string>()
            {
                { "UserName", userName }, { "RandomNum", Guid.NewGuid().ToString() }
            });
            var userInfo = CurrentRepository.GetOne(e => e.UserName == userName, e => new { e.HeadUrl });

            redisHelper.Set(ConstData.UserLoginJwt + userName, token, TimeSpan.FromDays(5));
            return(new { userInfo, token });
        }
        public IActionResult Index()
        {
            var cacheKey     = "TheTime";
            var existingTime = _redis.Get(cacheKey);

            if (!string.IsNullOrEmpty(existingTime))
            {
                ViewBag.Message = "Fetched from cache : " + existingTime;
            }
            else
            {
                existingTime = DateTime.Now.ToString();
                _redis.Set(cacheKey, existingTime, expirationInSeconds: 30);
                ViewBag.Message = "Added to cache : " + existingTime;
            }

            return(View());
        }