springboot + redis集群

2020-03-31  本文已影响0人  fdsun
<!--Redis-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
</dependency>
spring.redis.password=密码
spring.redis.timeout=5000ms
spring.redis.cluster.nodes=集群节点 ip:port
spring.redis.jedis.pool.max-active=600
spring.redis.jedis.pool.max-idle=300
spring.redis.jedis.pool.min-idle=100
spring.redis.jedis.pool.max-wait=1000ms
@RunWith(SpringRunner.class)
@SpringBootTest
public class TestRedis {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void test() throws Exception {
        // 存
        stringRedisTemplate.opsForValue().set("key123", "value123");
        // 过期时间(一天)
        stringRedisTemplate.expire(key, 1000 * 60 * 60 * 24, TimeUnit.MILLISECONDS);
    }
    @Test
    public void test1() throws Exception {
        // 取
        Assert.assertEquals("111", stringRedisTemplate.opsForValue().get("key123"));
    }
}
上一篇 下一篇

猜你喜欢

热点阅读