Quantcast
Channel: RedisTemplate expire doesn't work - Stack Overflow
Viewing all articles
Browse latest Browse all 2

RedisTemplate expire doesn't work

0
0

I'm trying to test expire method in RedisTemplate. For example, I store session in redis, and than try to retrieve session and check that values are the same. For expire session I use expire() method of redisTemplate and for getting expired session I use getExpire() method. But it doesn't work. How can I test value, that stored in redis?

//without import and fields
public class Cache() {     

    private StringRedisTemplate redisTemplate;

    public boolean expireSession(String session, int duration) {
      return redisTemplate.expire(session, duration, TimeUnit.MINUTES);    
    } 
}

//Test class without imports and fields 
public class TestCache() {  

    private Cache cache = new Cache(); 
    @Test
    public void testExpireSession() {
        Integer duration = 16;
        String session = "SESSION_123";
        cache.expireSession(session, duration);
        assertEquals(redisTemplate.getExpire(session, TimeUnit.MINUTES), Long.valueOf(duration));    
    }    
}

but test fails with AssertionError:

Expected :16 Actual :0

UPDATE: I thought, that getExpire() method doesn't work, but in fact expire() method doesn't work. It returns false. redisTemplate is a spring Bean that autowired to test class. There are many other test methods in TestCache class that work correctly.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images