Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 解决强制依赖redis错误 #2015

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public WxMaConfig wxMaConfig() {
WxMaDefaultConfigImpl config;
switch (wxMaProperties.getConfigStorage().getType()) {
case Jedis:
config = wxMaJedisConfigStorage();
config = WxMaRedisBetterConfig.config(wxMaProperties, applicationContext);
break;
case RedisTemplate:
config = wxMaRedisTemplateConfigStorage();
Expand Down Expand Up @@ -107,35 +107,39 @@ private WxMaDefaultConfigImpl wxMaDefaultConfigStorage() {
return new WxMaDefaultConfigImpl();
}

private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
JedisPoolConfig config = new JedisPoolConfig();
if (redisProperties.getMaxActive() != null) {
config.setMaxTotal(redisProperties.getMaxActive());
}
if (redisProperties.getMaxIdle() != null) {
config.setMaxIdle(redisProperties.getMaxIdle());
}
if (redisProperties.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
}
if (redisProperties.getMinIdle() != null) {
config.setMinIdle(redisProperties.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);
private static class WxMaRedisBetterConfig {

jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
private static WxMaDefaultConfigImpl config(WxMaProperties wxMaProperties, ApplicationContext context) {
RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
JedisPoolConfig config = new JedisPoolConfig();
if (redisProperties.getMaxActive() != null) {
config.setMaxTotal(redisProperties.getMaxActive());
}
if (redisProperties.getMaxIdle() != null) {
config.setMaxIdle(redisProperties.getMaxIdle());
}
if (redisProperties.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
}
if (redisProperties.getMinIdle() != null) {
config.setMinIdle(redisProperties.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);

jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
} else {
jedisPool = context.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
}


private WxMaDefaultConfigImpl wxMaRedisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
Expand Down