add 增加 redis redisson 集群配置
This commit is contained in:
parent
9bc5414b44
commit
5285735c7a
@ -70,7 +70,7 @@ spring:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
|
||||
--- # redis 配置
|
||||
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring:
|
||||
redis:
|
||||
# 地址
|
||||
@ -118,6 +118,67 @@ redisson:
|
||||
# DNS监测时间间隔,单位:毫秒
|
||||
dnsMonitoringInterval: 5000
|
||||
|
||||
#--- # redis 集群配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
#spring:
|
||||
# redis:
|
||||
# cluster:
|
||||
# nodes:
|
||||
# - 192.168.0.100:6379
|
||||
# - 192.168.0.101:6379
|
||||
# - 192.168.0.102:6379
|
||||
# # 密码
|
||||
# password:
|
||||
# # 连接超时时间
|
||||
# timeout: 10s
|
||||
# # 是否开启ssl
|
||||
# ssl: false
|
||||
#
|
||||
#redisson:
|
||||
# # 线程池数量
|
||||
# threads: 16
|
||||
# # Netty线程池数量
|
||||
# nettyThreads: 32
|
||||
# # 传输模式
|
||||
# transportMode: "NIO"
|
||||
# # 集群配置
|
||||
# clusterServersConfig:
|
||||
# # 客户端名称
|
||||
# clientName: ${ruoyi.name}
|
||||
# # master最小空闲连接数
|
||||
# masterConnectionMinimumIdleSize: 32
|
||||
# # master连接池大小
|
||||
# masterConnectionPoolSize: 64
|
||||
# # slave最小空闲连接数
|
||||
# slaveConnectionMinimumIdleSize: 32
|
||||
# # slave连接池大小
|
||||
# slaveConnectionPoolSize: 64
|
||||
# # 连接空闲超时,单位:毫秒
|
||||
# idleConnectionTimeout: 10000
|
||||
# # ping连接间隔
|
||||
# pingConnectionInterval: 1000
|
||||
# # 命令等待超时,单位:毫秒
|
||||
# timeout: 3000
|
||||
# # 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。
|
||||
# retryAttempts: 3
|
||||
# # 命令重试发送时间间隔,单位:毫秒
|
||||
# retryInterval: 1500
|
||||
# # 从可用服务器的内部列表中排除 Redis Slave 重新连接尝试的间隔。
|
||||
# failedSlaveReconnectionInterval: 3000
|
||||
# # 发布和订阅连接池最小空闲连接数
|
||||
# subscriptionConnectionMinimumIdleSize: 1
|
||||
# # 发布和订阅连接池大小
|
||||
# subscriptionConnectionPoolSize: 50
|
||||
# # 单个连接最大订阅数量
|
||||
# subscriptionsPerConnection: 5
|
||||
# # 扫描间隔
|
||||
# scanInterval: 1000
|
||||
# # DNS监测时间间隔,单位:毫秒
|
||||
# dnsMonitoringInterval: 5000
|
||||
# # 读取模式
|
||||
# readMode: "SLAVE"
|
||||
# # 订阅模式
|
||||
# subscriptionMode: "MASTER"
|
||||
|
||||
--- # 监控配置
|
||||
spring:
|
||||
boot:
|
||||
|
@ -70,7 +70,7 @@ spring:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
|
||||
--- # redis 配置
|
||||
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
spring:
|
||||
redis:
|
||||
# 地址
|
||||
@ -118,6 +118,67 @@ redisson:
|
||||
# DNS监测时间间隔,单位:毫秒
|
||||
dnsMonitoringInterval: 5000
|
||||
|
||||
#--- # redis 集群配置(单机与集群只能开启一个另一个需要注释掉)
|
||||
#spring:
|
||||
# redis:
|
||||
# cluster:
|
||||
# nodes:
|
||||
# - 192.168.0.100:6379
|
||||
# - 192.168.0.101:6379
|
||||
# - 192.168.0.102:6379
|
||||
# # 密码
|
||||
# password:
|
||||
# # 连接超时时间
|
||||
# timeout: 10s
|
||||
# # 是否开启ssl
|
||||
# ssl: false
|
||||
#
|
||||
#redisson:
|
||||
# # 线程池数量
|
||||
# threads: 16
|
||||
# # Netty线程池数量
|
||||
# nettyThreads: 32
|
||||
# # 传输模式
|
||||
# transportMode: "NIO"
|
||||
# # 集群配置
|
||||
# clusterServersConfig:
|
||||
# # 客户端名称
|
||||
# clientName: ${ruoyi.name}
|
||||
# # master最小空闲连接数
|
||||
# masterConnectionMinimumIdleSize: 32
|
||||
# # master连接池大小
|
||||
# masterConnectionPoolSize: 64
|
||||
# # slave最小空闲连接数
|
||||
# slaveConnectionMinimumIdleSize: 32
|
||||
# # slave连接池大小
|
||||
# slaveConnectionPoolSize: 64
|
||||
# # 连接空闲超时,单位:毫秒
|
||||
# idleConnectionTimeout: 10000
|
||||
# # ping连接间隔
|
||||
# pingConnectionInterval: 1000
|
||||
# # 命令等待超时,单位:毫秒
|
||||
# timeout: 3000
|
||||
# # 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。
|
||||
# retryAttempts: 3
|
||||
# # 命令重试发送时间间隔,单位:毫秒
|
||||
# retryInterval: 1500
|
||||
# # 从可用服务器的内部列表中排除 Redis Slave 重新连接尝试的间隔。
|
||||
# failedSlaveReconnectionInterval: 3000
|
||||
# # 发布和订阅连接池最小空闲连接数
|
||||
# subscriptionConnectionMinimumIdleSize: 1
|
||||
# # 发布和订阅连接池大小
|
||||
# subscriptionConnectionPoolSize: 50
|
||||
# # 单个连接最大订阅数量
|
||||
# subscriptionsPerConnection: 5
|
||||
# # 扫描间隔
|
||||
# scanInterval: 1000
|
||||
# # DNS监测时间间隔,单位:毫秒
|
||||
# dnsMonitoringInterval: 5000
|
||||
# # 读取模式
|
||||
# readMode: "SLAVE"
|
||||
# # 订阅模式
|
||||
# subscriptionMode: "MASTER"
|
||||
|
||||
--- # 监控配置
|
||||
spring:
|
||||
boot:
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.ruoyi.framework.config;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.framework.config.properties.RedissonProperties;
|
||||
@ -58,23 +59,52 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||
.setTransportMode(redissonProperties.getTransportMode());
|
||||
|
||||
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
||||
// 使用单机模式
|
||||
config.useSingleServer()
|
||||
.setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort())
|
||||
.setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue())
|
||||
.setDatabase(redisProperties.getDatabase())
|
||||
.setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null)
|
||||
.setTimeout(singleServerConfig.getTimeout())
|
||||
.setRetryAttempts(singleServerConfig.getRetryAttempts())
|
||||
.setRetryInterval(singleServerConfig.getRetryInterval())
|
||||
.setSubscriptionsPerConnection(singleServerConfig.getSubscriptionsPerConnection())
|
||||
.setClientName(singleServerConfig.getClientName())
|
||||
.setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout())
|
||||
.setSubscriptionConnectionMinimumIdleSize(singleServerConfig.getSubscriptionConnectionMinimumIdleSize())
|
||||
.setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize())
|
||||
.setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize())
|
||||
.setConnectionPoolSize(singleServerConfig.getConnectionPoolSize())
|
||||
.setDnsMonitoringInterval(singleServerConfig.getDnsMonitoringInterval());
|
||||
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
||||
// 使用单机模式
|
||||
config.useSingleServer()
|
||||
.setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort())
|
||||
.setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue())
|
||||
.setDatabase(redisProperties.getDatabase())
|
||||
.setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null)
|
||||
.setTimeout(singleServerConfig.getTimeout())
|
||||
.setRetryAttempts(singleServerConfig.getRetryAttempts())
|
||||
.setRetryInterval(singleServerConfig.getRetryInterval())
|
||||
.setSubscriptionsPerConnection(singleServerConfig.getSubscriptionsPerConnection())
|
||||
.setClientName(singleServerConfig.getClientName())
|
||||
.setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout())
|
||||
.setSubscriptionConnectionMinimumIdleSize(singleServerConfig.getSubscriptionConnectionMinimumIdleSize())
|
||||
.setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize())
|
||||
.setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize())
|
||||
.setConnectionPoolSize(singleServerConfig.getConnectionPoolSize())
|
||||
.setDnsMonitoringInterval(singleServerConfig.getDnsMonitoringInterval());
|
||||
}
|
||||
|
||||
RedissonProperties.ClusterServersConfig clusterServersConfig = redissonProperties.getClusterServersConfig();
|
||||
if (ObjectUtil.isNotNull(clusterServersConfig)) {
|
||||
// 使用集群模式
|
||||
config.useClusterServers()
|
||||
.setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue())
|
||||
.setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null)
|
||||
.setTimeout(clusterServersConfig.getTimeout())
|
||||
.setRetryAttempts(clusterServersConfig.getRetryAttempts())
|
||||
.setRetryInterval(clusterServersConfig.getRetryInterval())
|
||||
.setSubscriptionsPerConnection(clusterServersConfig.getSubscriptionsPerConnection())
|
||||
.setClientName(clusterServersConfig.getClientName())
|
||||
.setIdleConnectionTimeout(clusterServersConfig.getIdleConnectionTimeout())
|
||||
.setPingConnectionInterval(clusterServersConfig.getPingConnectionInterval())
|
||||
.setSubscriptionConnectionMinimumIdleSize(clusterServersConfig.getSubscriptionConnectionMinimumIdleSize())
|
||||
.setSubscriptionConnectionPoolSize(clusterServersConfig.getSubscriptionConnectionPoolSize())
|
||||
.setMasterConnectionMinimumIdleSize(clusterServersConfig.getMasterConnectionMinimumIdleSize())
|
||||
.setMasterConnectionPoolSize(clusterServersConfig.getMasterConnectionPoolSize())
|
||||
.setSlaveConnectionMinimumIdleSize(clusterServersConfig.getSlaveConnectionMinimumIdleSize())
|
||||
.setSlaveConnectionPoolSize(clusterServersConfig.getSlaveConnectionPoolSize())
|
||||
.setDnsMonitoringInterval(clusterServersConfig.getDnsMonitoringInterval())
|
||||
.setFailedSlaveReconnectionInterval(clusterServersConfig.getFailedSlaveReconnectionInterval())
|
||||
.setScanInterval(clusterServersConfig.getScanInterval())
|
||||
.setReadMode(clusterServersConfig.getReadMode())
|
||||
.setSubscriptionMode(clusterServersConfig.getSubscriptionMode())
|
||||
.setNodeAddresses(redisProperties.getCluster().getNodes());
|
||||
}
|
||||
RedissonClient redissonClient = Redisson.create(config);
|
||||
log.info("初始化 redis 配置");
|
||||
return redissonClient;
|
||||
|
@ -2,6 +2,8 @@ package com.ruoyi.framework.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.redisson.config.ReadMode;
|
||||
import org.redisson.config.SubscriptionMode;
|
||||
import org.redisson.config.TransportMode;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -38,6 +40,11 @@ public class RedissonProperties {
|
||||
*/
|
||||
private SingleServerConfig singleServerConfig;
|
||||
|
||||
/**
|
||||
* 集群服务配置
|
||||
*/
|
||||
private ClusterServersConfig clusterServersConfig;
|
||||
|
||||
/**
|
||||
* 缓存组
|
||||
*/
|
||||
@ -104,6 +111,102 @@ public class RedissonProperties {
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class ClusterServersConfig {
|
||||
|
||||
/**
|
||||
* 客户端名称
|
||||
*/
|
||||
private String clientName;
|
||||
|
||||
/**
|
||||
* master最小空闲连接数
|
||||
*/
|
||||
private int masterConnectionMinimumIdleSize;
|
||||
|
||||
/**
|
||||
* master连接池大小
|
||||
*/
|
||||
private int masterConnectionPoolSize;
|
||||
|
||||
/**
|
||||
* slave最小空闲连接数
|
||||
*/
|
||||
private int slaveConnectionMinimumIdleSize;
|
||||
|
||||
/**
|
||||
* slave连接池大小
|
||||
*/
|
||||
private int slaveConnectionPoolSize;
|
||||
|
||||
/**
|
||||
* 连接空闲超时,单位:毫秒
|
||||
*/
|
||||
private int idleConnectionTimeout;
|
||||
|
||||
/**
|
||||
* ping超时
|
||||
*/
|
||||
private int pingConnectionInterval;
|
||||
|
||||
/**
|
||||
* 命令等待超时,单位:毫秒
|
||||
*/
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* 如果尝试在此限制之内发送成功,则开始启用 timeout 计时。
|
||||
*/
|
||||
private int retryAttempts;
|
||||
|
||||
/**
|
||||
* 命令重试发送时间间隔,单位:毫秒
|
||||
*/
|
||||
private int retryInterval;
|
||||
|
||||
/**
|
||||
* 错误重试次数
|
||||
*/
|
||||
private int failedSlaveReconnectionInterval;
|
||||
|
||||
/**
|
||||
* 发布和订阅连接池最小空闲连接数
|
||||
*/
|
||||
private int subscriptionConnectionMinimumIdleSize;
|
||||
|
||||
/**
|
||||
* 发布和订阅连接池大小
|
||||
*/
|
||||
private int subscriptionConnectionPoolSize;
|
||||
|
||||
/**
|
||||
* 单个连接最大订阅数量
|
||||
*/
|
||||
private int subscriptionsPerConnection;
|
||||
|
||||
/**
|
||||
* 扫描间隔
|
||||
*/
|
||||
private int scanInterval;
|
||||
|
||||
/**
|
||||
* DNS监测时间间隔,单位:毫秒
|
||||
*/
|
||||
private int dnsMonitoringInterval;
|
||||
|
||||
/**
|
||||
* 读取模式
|
||||
*/
|
||||
private ReadMode readMode;
|
||||
|
||||
/**
|
||||
* 订阅模式
|
||||
*/
|
||||
private SubscriptionMode subscriptionMode;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class CacheGroup {
|
||||
|
Loading…
x
Reference in New Issue
Block a user