|
@@ -10,6 +10,7 @@ import com.yomahub.liteflow.log.LFLog;
|
|
|
import com.yomahub.liteflow.log.LFLoggerManager;
|
|
|
import com.yomahub.liteflow.parser.redis.vo.RedisParserVO;
|
|
|
import org.redisson.config.Config;
|
|
|
+import org.redisson.config.SentinelServersConfig;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
@@ -24,7 +25,9 @@ public interface RedisParserHelper {
|
|
|
|
|
|
LFLog LOG = LFLoggerManager.getLogger(RedisParserHelper.class);
|
|
|
|
|
|
- String REDIS_URL_PATTERN = "redis://{}:{}";
|
|
|
+ String SINGLE_REDIS_URL_PATTERN = "redis://{}:{}";
|
|
|
+
|
|
|
+ String SENTINEL_REDIS_URL_PATTERN = "redis://{}";
|
|
|
|
|
|
String CHAIN_XML_PATTERN = "<chain name=\"{}\">{}</chain>";
|
|
|
|
|
@@ -42,16 +45,23 @@ public interface RedisParserHelper {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 获取Redisson客户端的Config配置通用方法
|
|
|
+ * 获取Redisson客户端的Config配置通用方法(单点模式)
|
|
|
* @param redisParserVO redisParserVO
|
|
|
- * @param dataBase redisson连接的数据库号
|
|
|
+ * @param dataBase redis连接的数据库号
|
|
|
* @return redisson config
|
|
|
*/
|
|
|
- default Config getRedissonConfig(RedisParserVO redisParserVO, Integer dataBase) {
|
|
|
+ default Config getSingleRedissonConfig(RedisParserVO redisParserVO, Integer dataBase) {
|
|
|
Config config = new Config();
|
|
|
- String redisAddress = StrFormatter.format(REDIS_URL_PATTERN, redisParserVO.getHost(), redisParserVO.getPort());
|
|
|
+ String redisAddress = StrFormatter.format(SINGLE_REDIS_URL_PATTERN, redisParserVO.getHost(), redisParserVO.getPort());
|
|
|
+ //如果配置了用户名和密码
|
|
|
+ if (StrUtil.isNotBlank(redisParserVO.getUsername()) && StrUtil.isNotBlank(redisParserVO.getPassword())) {
|
|
|
+ config.useSingleServer().setAddress(redisAddress)
|
|
|
+ .setUsername(redisParserVO.getUsername())
|
|
|
+ .setPassword(redisParserVO.getPassword())
|
|
|
+ .setDatabase(dataBase);
|
|
|
+ }
|
|
|
//如果配置了密码
|
|
|
- if (StrUtil.isNotBlank(redisParserVO.getPassword())) {
|
|
|
+ else if (StrUtil.isNotBlank(redisParserVO.getPassword())) {
|
|
|
config.useSingleServer().setAddress(redisAddress)
|
|
|
.setPassword(redisParserVO.getPassword())
|
|
|
.setDatabase(dataBase);
|
|
@@ -64,6 +74,37 @@ public interface RedisParserHelper {
|
|
|
return config;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取Redisson客户端的Config配置通用方法(哨兵模式)
|
|
|
+ * @param redisParserVO redisParserVO
|
|
|
+ * @param dataBase redis连接的数据库号
|
|
|
+ * @return redisson Config
|
|
|
+ */
|
|
|
+ default Config getSentinelRedissonConfig(RedisParserVO redisParserVO, Integer dataBase) {
|
|
|
+ Config config = new Config();
|
|
|
+ SentinelServersConfig sentinelConfig = config.useSentinelServers()
|
|
|
+ .setMasterName(redisParserVO.getMasterName());
|
|
|
+ redisParserVO.getSentinelAddress().forEach(address -> {
|
|
|
+ sentinelConfig.addSentinelAddress(StrFormatter.format(SENTINEL_REDIS_URL_PATTERN, address));
|
|
|
+ });
|
|
|
+ //如果配置了用户名和密码
|
|
|
+ if(StrUtil.isNotBlank(redisParserVO.getUsername()) && StrUtil.isNotBlank(redisParserVO.getPassword())) {
|
|
|
+ sentinelConfig.setUsername(redisParserVO.getUsername())
|
|
|
+ .setPassword(redisParserVO.getPassword())
|
|
|
+ .setDatabase(dataBase);
|
|
|
+ }
|
|
|
+ //如果配置了密码
|
|
|
+ else if(StrUtil.isNotBlank(redisParserVO.getPassword())) {
|
|
|
+ sentinelConfig.setPassword(redisParserVO.getPassword())
|
|
|
+ .setDatabase(dataBase);
|
|
|
+ }
|
|
|
+ //没有配置密码
|
|
|
+ else {
|
|
|
+ sentinelConfig.setDatabase(dataBase);
|
|
|
+ }
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* script节点的修改/添加
|
|
|
*
|