admin
2022-01-12 4a7367a869ef12375ea6678ca44e102b8919c624
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.ks;
 
import com.ks.push.PushApplication;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
 
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
 
@SpringBootTest(classes = PushApplication.class)
@ContextConfiguration
public class RedisTest {
 
    @Resource
    private RedisTemplate redisTemplate;
 
 
    @Test
    public void getTime() throws InterruptedException {
        String timeKey = "test-";
        redisTemplate.opsForValue().set(timeKey, "1", 2, TimeUnit.SECONDS);
        long time1 = (redisTemplate.getExpire(timeKey));
        Thread.sleep(2000);
         time1 = (redisTemplate.getExpire(timeKey));
        Thread.sleep(2000);
         time1 = (redisTemplate.getExpire(timeKey));
    }
 
}