in server/src/main/java/org/apache/seata/server/storage/redis/JedisPooledFactory.java [65:125]
public static JedisPoolAbstract getJedisPoolInstance(JedisPoolAbstract... jedisPools) {
if (jedisPool == null) {
synchronized (JedisPooledFactory.class) {
if (jedisPool == null) {
JedisPoolAbstract tempJedisPool = null;
if (jedisPools != null && jedisPools.length > 0) {
tempJedisPool = jedisPools[0];
} else {
String password = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_PASSWORD);
if (StringUtils.isBlank(password)) {
password = null;
} else {
String publicKey = CONFIGURATION.getConfig(ConfigurationKeys.STORE_PUBLIC_KEY);
if (StringUtils.isNotBlank(publicKey)) {
try {
password = ConfigTools.publicDecrypt(password, publicKey);
} catch (Exception e) {
LOGGER.error("decryption failed,please confirm whether the ciphertext and secret key are correct! error msg: {}", e.getMessage());
}
}
}
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMinIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MIN_CONN,
DEFAULT_REDIS_MIN_IDLE));
poolConfig.setMaxIdle(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_CONN,
DEFAULT_REDIS_MAX_IDLE));
poolConfig.setMaxTotal(CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_MAX_TOTAL, DEFAULT_REDIS_MAX_TOTAL));
String mode = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_MODE,ConfigurationKeys.REDIS_SINGLE_MODE);
if (mode.equals(ConfigurationKeys.REDIS_SENTINEL_MODE)) {
String masterName = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_MASTERNAME);
if (StringUtils.isBlank(masterName)) {
throw new RedisException("The masterName is null in redis sentinel mode");
}
Set<String> sentinels = new HashSet<>(SENTINEL_HOST_NUMBER);
String[] sentinelHosts = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_HOST).split(",");
Arrays.asList(sentinelHosts).forEach(sentinelHost -> sentinels.add(sentinelHost));
String sentinelPassword = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SENTINEL_PASSWORD);
if (StringUtils.isBlank(sentinelPassword)) {
sentinelPassword = null;
}
tempJedisPool = new JedisSentinelPool(masterName, sentinels, poolConfig, 60000, 60000, password, CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_DATABASE, DATABASE),
null, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, sentinelPassword, null);
} else if (mode.equals(ConfigurationKeys.REDIS_SINGLE_MODE)) {
String host = CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_SINGLE_HOST);
host = StringUtils.isBlank(host) ? CONFIGURATION.getConfig(ConfigurationKeys.STORE_REDIS_HOST, HOST) : host;
int port = CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_SINGLE_PORT);
port = port == 0 ? CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_PORT, PORT) : port;
tempJedisPool = new JedisPool(poolConfig, host, port, 60000, password, CONFIGURATION.getInt(ConfigurationKeys.STORE_REDIS_DATABASE, DATABASE));
} else {
throw new RedisException("Configuration error of redis cluster mode");
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("initialization of the build redis connection pool is complete");
}
jedisPool = tempJedisPool;
}
}
}
return jedisPool;
}