SpringBoot 2.x版本整合Redis集群
2020-03-15 22:37
916 查看
SpringBoot 2.x版本整合redis集群
启动 Redis集群 搭建方式
SpringBoot 1.x版本默认使用jedis 连接,2.x版本使用lettuce连接
导入依赖
<!-- redis缓存 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-redis</artifactId> <version>1.4.7.RELEASE</version> </dependency>
yml
spring: redis: cluster: nodes: - 127.0.1.1:7001 - 127.0.1.1:7002 - 127.0.1.1:7003 - 127.0.1.1:7004 - 127.0.1.1:7005 - 127.0.1.1:7006 max-redirects: 3 # 获取失败 最大重定向次数 pool: max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) max-idle: 10 # 连接池中的最大空闲连接 max-wait: -1 # 连接池最大阻塞等待时间(使用负值表示没有限制) min-idle: 5 # 连接池中的最小空闲连接 timeout: 6000 # 连接超时时长(毫秒)
使用默认的连接池
使用jedis连接池
<!-- 使用jedis连接池--> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> </dependency>
yml
spring: redis: password: # 密码(默认为空) timeout: 6000ms # 连接超时时长(毫秒) cluster: nodes: - 127.0.1.1:7001 - 127.0.1.1:7002 - 127.0.1.1:7003 - 127.0.1.1:7004 - 127.0.1.1:7005 - 127.0.1.1:7006 jedis: pool: max-active: 1000 # 连接池最大连接数(使用负值表示没有限制) max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) max-idle: 10 # 连接池中的最大空闲连接 min-idle: 5 # 连接池中的最小空闲连接
测试
@Autowired RedisTemplate redisTemplate; @Test public void test1(){ redisTemplate.opsForValue().set("k2","k123"); System.out.println(redisTemplate.opsForValue().get("k")); }
相关文章推荐
- redis集群 与springboot 整合步骤 (linux版本)
- SpringBoot整合Redis(单机+集群) —— 含Spring版附件文档
- Springboot2.x集成Redis集群模式
- SpringBoot整合Thymeleaf-基于SpringBoot2.X版本
- SpringBoot整合Redis集群
- SpringBoot 2.x整合Redis实现RedisTemplate以及缓存
- Spring Boot2.0之 整合Redis集群
- SpringBoot2.X 整合RedisTemplate 简单实现消息队列
- Springboot整合Redis-sentinel哨兵模式集群
- 9.springboot2.X整合redis-shiro
- 深度解析SpringBoot2.x整合Spring-Data-Redis
- springboot+shiro+redis(集群redis版)整合教程
- Springboot2.X集成redis集群(Lettuce)连接的方法
- SpringBoot 2.0及以上版本整合redis
- SpringBoot整合Redis集群
- SpringBoot整合Thymeleaf-基于SpringBoot2.X版本
- redis学习系列(二)--spring boot整合Redis集群
- Redis学习(三)——SpringBoot整合Redis-5.0.4集群
- springboot2.x+redis整合
- spring boot整合redis(单机+集群)