springboot整合rediss集群
时间: 2023-12-18 17:29:46 浏览: 74
以下是Spring Boot整合Redisson集群的步骤:
1.在pom.xml文件中添加Redisson依赖:
```xml
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.15.5</version>
</dependency>
```
2.在application.properties文件中配置Redisson:
```properties
# Redisson配置
spring.redis.redisson.config=classpath:redisson.yaml
```
3.在resources目录下创建redisson.yaml文件,并配置Redisson集群:
```yaml
clusterServersConfig:
idleConnectionTimeout: 10000
pingTimeout: 1000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
reconnectionTimeout: 3000
failedAttempts: 3
password: null
subscriptionsPerConnection: 5
clientName: null
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
slaveConnectionMinimumIdleSize: 32
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 32
masterConnectionPoolSize: 64
readMode: "SLAVE"
subscriptionMode: "SLAVE"
nodeAddresses:
- "redis://127.0.0.1:7000"
- "redis://127.0.0.1:7001"
- "redis://127.0.0.1:7002"
- "redis://127.0.0.1:7003"
- "redis://127.0.0.1:7004"
- "redis://127.0.0.1:7005"
```
4.在代码中使用Redisson:
```java
@Service
public class RedissonService {
@Autowired
private RedissonClient redissonClient;
public void set(String key, String value) {
RBucket<String> bucket = redissonClient.getBucket(key);
bucket.set(value);
}
public String get(String key) {
RBucket<String> bucket = redissonClient.getBucket(key);
return bucket.get();
}
}
```
以上就是Spring Boot整合Redisson集群的步骤。
阅读全文