sql >> Databasteknik >  >> NoSQL >> Redis

RedisTemplate expire fungerar inte

Jag ställer in följande kod för att utföra ett test på getExpire() (jedis 2.5.2, spring-data-redis 1.4.2.RELEASE):

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = DemoApplication.class)
public class DemoApplicationTests {

    @Autowired
    private RedisTemplate<String, String> template;

    @Test
    public void contextLoads() {

        template.getConnectionFactory().getConnection().flushAll();

        assertFalse(template.hasKey("key"));
        assertFalse(template.expire("key", 10, TimeUnit.MINUTES));
        assertEquals(0, template.getExpire("key", TimeUnit.MINUTES).longValue());

        template.opsForHash().put("key", "hashkey", "hashvalue");

        assertTrue(template.hasKey("key"));
        assertTrue(template.expire("key", 10, TimeUnit.MINUTES));
        assertTrue(template.getExpire("key", TimeUnit.MINUTES) > 8);
    }

}

Beroende på din Redis-konfiguration försvinner all Redis-data om du startar om din Redis-instans.

Du bör också lägga till ett påstående i expireSession (assertTrue(cache.expireSession(session, duration)); ) för att vara säker på att utgången fungerade.




  1. Mongoose lovar dokumentation säger att frågor inte är löften?

  2. Synkronisera MongoDB via ssh

  3. Bästa praxis för att uppgradera Redis med Sentinels?

  4. Node - Mongoose 3.6 - Sortera fråga med ifyllt fält