sql >> データベース >  >> NoSQL >> Redis

RedisTemplateの有効期限が機能しません

    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);
        }
    
    }
    

    Redisの構成によっては、Redisインスタンスを再起動するとすべてのRedisデータが失われます。

    expireSessionにもアサーションを追加する必要があります (assertTrue(cache.expireSession(session, duration)); )念のため、有効期限は機能しました。




    1. フィールド名ClassNameがmorphiaによってmongodbに挿入されています

    2. MongoDB $ lookup Objectidは空の配列を取得しますか?

    3. MongoDBのカーソルとは何ですか?

    4. 接続できないherokuにredisをデプロイする