美文网首页
springboot + redis集群

springboot + redis集群

作者: fdsun | 来源:发表于2020-03-31 13:33 被阅读0次
  • 1 pom.xml依赖
<!--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>
  • 2 application.properties配置
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
  • 3 使用
@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"));
    }
}

相关文章

网友评论

      本文标题:springboot + redis集群

      本文链接:https://www.haomeiwen.com/subject/ozjwuhtx.html