spring-boot-starter-parent 1.5.6.RELEASE 配置redis集群
时间: 2023-12-15 22:06:14 浏览: 86
以下是配置Redis集群的步骤:
1.在pom.xml文件中添加以下依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
```
2.在application.properties文件中添加以下配置:
```properties
# Redis Cluster Configuration
spring.redis.cluster.nodes=127.0.0.1:7001,127.0.0.1:7002,127.0.0.1:7003,127.0.0.1:7004,127.0.0.1:7005,127.0.0.1:7006
spring.redis.cluster.max-redirects=3
```
3.创建RedisConfig.java文件并添加以下内容:
```java
@Configuration
public class RedisConfig {
@Bean
public JedisCluster jedisCluster() {
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("127.0.0.1", 7001));
nodes.add(new HostAndPort("127.0.0.1", 7002));
nodes.add(new HostAndPort("127.0.0.1", 7003));
nodes.add(new HostAndPort("127.0.0.1", 7004));
nodes.add(new HostAndPort("127.0.0.1", 7005));
nodes.add(new HostAndPort("127.0.0.1", 7006));
return new JedisCluster(nodes);
}
}
```
4.在需要使用Redis的类中注入JedisCluster对象并使用即可。
阅读全文
相关推荐


