add 增加 redis redisson 集群配置
This commit is contained in:
parent
9bc5414b44
commit
5285735c7a
@ -70,7 +70,7 @@ spring:
|
|||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
|
||||||
--- # redis 配置
|
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||||
spring:
|
spring:
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
@ -118,6 +118,67 @@ redisson:
|
|||||||
# DNS监测时间间隔,单位:毫秒
|
# DNS监测时间间隔,单位:毫秒
|
||||||
dnsMonitoringInterval: 5000
|
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:
|
spring:
|
||||||
boot:
|
boot:
|
||||||
|
@ -70,7 +70,7 @@ spring:
|
|||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
|
||||||
--- # redis 配置
|
--- # redis 单机配置(单机与集群只能开启一个另一个需要注释掉)
|
||||||
spring:
|
spring:
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
@ -118,6 +118,67 @@ redisson:
|
|||||||
# DNS监测时间间隔,单位:毫秒
|
# DNS监测时间间隔,单位:毫秒
|
||||||
dnsMonitoringInterval: 5000
|
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:
|
spring:
|
||||||
boot:
|
boot:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.framework.config;
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.framework.config.properties.RedissonProperties;
|
import com.ruoyi.framework.config.properties.RedissonProperties;
|
||||||
@ -58,23 +59,52 @@ public class RedisConfig extends CachingConfigurerSupport {
|
|||||||
.setTransportMode(redissonProperties.getTransportMode());
|
.setTransportMode(redissonProperties.getTransportMode());
|
||||||
|
|
||||||
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
RedissonProperties.SingleServerConfig singleServerConfig = redissonProperties.getSingleServerConfig();
|
||||||
// 使用单机模式
|
if (ObjectUtil.isNotNull(singleServerConfig)) {
|
||||||
config.useSingleServer()
|
// 使用单机模式
|
||||||
.setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort())
|
config.useSingleServer()
|
||||||
.setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue())
|
.setAddress(prefix + redisProperties.getHost() + ":" + redisProperties.getPort())
|
||||||
.setDatabase(redisProperties.getDatabase())
|
.setConnectTimeout(((Long) redisProperties.getTimeout().toMillis()).intValue())
|
||||||
.setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null)
|
.setDatabase(redisProperties.getDatabase())
|
||||||
.setTimeout(singleServerConfig.getTimeout())
|
.setPassword(StringUtils.isNotBlank(redisProperties.getPassword()) ? redisProperties.getPassword() : null)
|
||||||
.setRetryAttempts(singleServerConfig.getRetryAttempts())
|
.setTimeout(singleServerConfig.getTimeout())
|
||||||
.setRetryInterval(singleServerConfig.getRetryInterval())
|
.setRetryAttempts(singleServerConfig.getRetryAttempts())
|
||||||
.setSubscriptionsPerConnection(singleServerConfig.getSubscriptionsPerConnection())
|
.setRetryInterval(singleServerConfig.getRetryInterval())
|
||||||
.setClientName(singleServerConfig.getClientName())
|
.setSubscriptionsPerConnection(singleServerConfig.getSubscriptionsPerConnection())
|
||||||
.setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout())
|
.setClientName(singleServerConfig.getClientName())
|
||||||
.setSubscriptionConnectionMinimumIdleSize(singleServerConfig.getSubscriptionConnectionMinimumIdleSize())
|
.setIdleConnectionTimeout(singleServerConfig.getIdleConnectionTimeout())
|
||||||
.setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize())
|
.setSubscriptionConnectionMinimumIdleSize(singleServerConfig.getSubscriptionConnectionMinimumIdleSize())
|
||||||
.setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize())
|
.setSubscriptionConnectionPoolSize(singleServerConfig.getSubscriptionConnectionPoolSize())
|
||||||
.setConnectionPoolSize(singleServerConfig.getConnectionPoolSize())
|
.setConnectionMinimumIdleSize(singleServerConfig.getConnectionMinimumIdleSize())
|
||||||
.setDnsMonitoringInterval(singleServerConfig.getDnsMonitoringInterval());
|
.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);
|
RedissonClient redissonClient = Redisson.create(config);
|
||||||
log.info("初始化 redis 配置");
|
log.info("初始化 redis 配置");
|
||||||
return redissonClient;
|
return redissonClient;
|
||||||
|
@ -2,6 +2,8 @@ package com.ruoyi.framework.config.properties;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.redisson.config.ReadMode;
|
||||||
|
import org.redisson.config.SubscriptionMode;
|
||||||
import org.redisson.config.TransportMode;
|
import org.redisson.config.TransportMode;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -38,6 +40,11 @@ public class RedissonProperties {
|
|||||||
*/
|
*/
|
||||||
private SingleServerConfig singleServerConfig;
|
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
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public static class CacheGroup {
|
public static class CacheGroup {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user