dimanche 24 mai 2015

RedisTemplate getExpire doesn't work

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() {     
    public void expireSession(String session) {
      this.redisTemplate.expire(session, 30, TimeUnit.MINUTES);    
    } 
}

//Test class without imports and fields 
public class TestCache() {   
    @Test
    public void testExpireSession() {
        Integer duration = 16;
        String session = "SESSION_123";
        cache.expireSession(session);
        assertEquals(redisTemplate.getExpire(session, TimeUnit.MINUTES), Long.valueOf(duration));    
    }    
}

but test fails with AssertionError:

Expected :16 Actual :0

Aucun commentaire:

Enregistrer un commentaire