0
    @RequestMapping("/loginByEmail")
    @GlobalInterceptor(checkParams = true)
    public ResponseVO loginByEmail(HttpSession httpSession,
                            HttpServletRequest request,
                            @VerifyParam(required = true, param = "email") String email,
                            @VerifyParam(required = true, param = "password") String password,
                            @VerifyParam(required = true, param = "checkCode") String checkCode) {


        try {
            
//            if (!checkCode.equalsIgnoreCase((String) httpSession.getAttribute(CHECK_CODE_KEY))) {
//                throw new BusinessException("wrong code");
//            }

          
            String token = loginService.loginByEmail(email, password, getIpAddress(request));
            httpSession.setAttribute(Constants.SESSION_KEY, token);


            
            return getSuccessResponseVO(token);

        } finally {
            redisTemplate.setKeySerializer(new StringRedisSerializer());
            redisTemplate.setValueSerializer(new StringRedisSerializer());
            redisTemplate.setHashKeySerializer(new StringRedisSerializer());
            redisTemplate.setHashValueSerializer(new StringRedisSerializer());
            redisTemplate.opsForValue().set("2","2");
            redisTemplate.expire("2", 1, TimeUnit.DAYS);
            System.out.println(RedisPrefixConstants.SPRING_SESSION_SESSIONS + httpSession.getId());
            httpSession.removeAttribute(CHECK_CODE_KEY);
        }

    }

I tried to test if i can store a data in redis and change it ttl and i succeed but when i change the data that spring session store in redis, i cannot change it. the key is definitely correct because ive already compared. and i dont know why i cannot change it.

1
  • What is the type of redisTemplate and what library are you using (e.g., lettuce)?
    – Blake
    Commented Mar 14 at 9:44

1 Answer 1

0

Ok i got the answer. Here it is: The TTL of the data in the Spring session cannot be modified by the redisTemplate.expire () method, because the TTL in the spring session is controlled by its own maxInactiveInterval. So if you want to change it time, you need to directly change the session expiration time to control it TTL.

You can use:

httpSession.setMaxInactiveInterval(300000); // 3000000 in seconds

Not the answer you're looking for? Browse other questions tagged or ask your own question.