spring: redis: port: 6379 host: 192.168.88.101 password: 111111 lettuce: pool: max-active: 8 max-wait: -1ms database: 0
yml配置(单机版)
spring: redis: password: 111111 lettuce: cluster: refresh: adaptive: true period: 2000 cluster: max-redirects: 3 nodes: ip:port,ip:port,ip:port,ip:port,ip:port,ip:port
yml配置(集群版),同时支持集群拓扑动态感应刷新
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.7.2</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> <version>2.11.1</version> </dependency>
相关依赖
@Autowired private StringRedisTemplate redisTemplate; //这里我使用的是stringredistemplate而不是redistemplate,主要是我懒得写那个配置类了。。。 public void add(String key,String value){ redisTemplate.opsForValue().set(key,value); } public String getById(Integer id){ return redisTemplate.opsForValue().get(ORDER_KEY+id); }
service层实现
标签:springboot,spring,redis,整合,ip,port,redisTemplate,String From: https://www.cnblogs.com/kun1790051360/p/17877932.html