|
@@ -42,7 +42,15 @@ public class JedisProviderFactoryBean implements ApplicationContextAware, Initia
|
|
|
|
|
|
private Pattern pattern = Pattern.compile("^.+[:]\\d{1,5}\\s*$");
|
|
|
|
|
|
- private String mode = JedisStandaloneProvider.MODE;
|
|
|
+
|
|
|
+ * mode(
|
|
|
+ * standalone:单机模式,
|
|
|
+ * sentinel:哨兵模式(主从),
|
|
|
+ * cluster:集群模式,
|
|
|
+ * shard:分片模式
|
|
|
+ * )
|
|
|
+ */
|
|
|
+ private String mode = JedisStandaloneProvider.MODE;
|
|
|
|
|
|
private JedisPoolConfig jedisPoolConfig;
|
|
|
|
|
@@ -120,11 +128,15 @@ public class JedisProviderFactoryBean implements ApplicationContextAware, Initia
|
|
|
*
|
|
|
*/
|
|
|
private void registerRedisProvier() {
|
|
|
+
|
|
|
+
|
|
|
String beanName = getGroup() + REDIS_PROVIDER_SUFFIX;
|
|
|
if (context.containsBean(beanName)) {
|
|
|
throw new RuntimeException("已包含group为[" + this.group + "]的缓存实例");
|
|
|
}
|
|
|
|
|
|
+ logger.info("注册 RedisProvier, group为[" + this.group + "]的缓存实例");
|
|
|
+
|
|
|
String[] servers = StringUtils.tokenizeToStringArray(this.servers, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
|
|
|
|
|
|
|
|
@@ -150,16 +162,23 @@ public class JedisProviderFactoryBean implements ApplicationContextAware, Initia
|
|
|
|
|
|
DefaultListableBeanFactory acf = (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory();
|
|
|
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(beanClass);
|
|
|
- beanDefinitionBuilder.addConstructorArgValue(getGroup())
|
|
|
- .addConstructorArgValue(jedisPoolConfig)
|
|
|
- .addConstructorArgValue(servers)
|
|
|
- .addConstructorArgValue(timeout);
|
|
|
+ beanDefinitionBuilder.addConstructorArgValue(getGroup())
|
|
|
+ .addConstructorArgValue(jedisPoolConfig)
|
|
|
+ .addConstructorArgValue(servers)
|
|
|
+ .addConstructorArgValue(timeout);
|
|
|
+
|
|
|
+ if (JedisStandaloneProvider.MODE.equalsIgnoreCase(mode)
|
|
|
+ || JedisSentinelProvider.MODE.equalsIgnoreCase(mode)
|
|
|
+ || JedisClusterProvider.MODE.equalsIgnoreCase(mode)) {
|
|
|
+
|
|
|
+ beanDefinitionBuilder.addConstructorArgValue(org.apache.commons.lang3.StringUtils.trimToNull(password));
|
|
|
+ }
|
|
|
|
|
|
if (JedisStandaloneProvider.MODE.equalsIgnoreCase(mode)
|
|
|
|| JedisSentinelProvider.MODE.equalsIgnoreCase(mode)) {
|
|
|
- beanDefinitionBuilder.addConstructorArgValue(org.apache.commons.lang3.StringUtils.trimToNull(password))
|
|
|
- .addConstructorArgValue(database)
|
|
|
- .addConstructorArgValue(clientName);
|
|
|
+
|
|
|
+ beanDefinitionBuilder.addConstructorArgValue(database)
|
|
|
+ .addConstructorArgValue(clientName);
|
|
|
}
|
|
|
|
|
|
if (JedisSentinelProvider.MODE.equalsIgnoreCase(mode)) {
|