强烈建议大家到 github
相关页面提交问题,方便统一查询管理,具体页面地址:https://github.com/Wechat-Group/WxJava/issues
当然如果必须在这里提问,请务必按以下格式填写,谢谢配合~
Redis集群,使用JedisCluster 报错
Pipeline is currently not supported for JedisClusterConn
WxJava
模块名: weixin-java-mpWxJava
版本号:4.4.0项目重使用的是redis集群,配置如下
Redis的配置
@Bean(name = "jedisPoolConfigCustom")
public JedisPoolConfig jedisPoolConfig(@Value("${spring.redis.jedis.pool.max-total:100}") int maxTotal,
@Value("${spring.redis.jedis.pool.max-wait:5000}") int maxWaitMillis,
@Value("${spring.redis.jedis.pool.max-idle:10}") int maxIdle) {
JedisPoolConfig config = new JedisPoolConfig();
// 最大连接数
config.setMaxTotal(maxTotal);
// 最小空闲连接数
config.setMaxIdle(maxIdle);
// 当池内没有可用的连接时,最大等待时间
config.setMaxWaitMillis(maxWaitMillis);
return config;
}
@Bean(name = "redisConnectionFactory")
public RedisConnectionFactory connectionFactory(@Qualifier("jedisPoolConfigCustom") @Autowired JedisPoolConfig jedisPoolConfig,
RedisProperties properties) {
// 获得默认的连接池构造
//修改我们的连接池配置
// 这里需要注意的是,edisConnectionFactoryJ对于Standalone模式的没有(RedisStandaloneConfiguration,JedisPoolConfig)的构造函数,对此
// 我们用JedisClientConfiguration接口的builder方法实例化一个构造器,还得类型转换
JedisClientConfiguration.JedisPoolingClientConfigurationBuilder jpcf = (JedisClientConfiguration.JedisPoolingClientConfigurationBuilder) JedisClientConfiguration.builder();
jpcf.poolConfig(jedisPoolConfig);
//通过构造器来构造jedis客户端配置
JedisClientConfiguration jedisClientConfiguration = jpcf.build();
//Jedis连接工厂 JedisConnectionFactory是RedisConnectionFactory子类
JedisConnectionFactory factory;
//RedisSentinelConfiguration 是 RedisConfiguration 的子类
RedisSentinelConfiguration sentinelConfig = getSentinelConfiguration(properties);
RedisClusterConfiguration clusterConfiguration = getClusterConfiguration(properties);
if (sentinelConfig != null) {
log.info("Redis Sentinel 集群配置...");
factory = new JedisConnectionFactory(sentinelConfig, jedisClientConfiguration);
} else if (clusterConfiguration != null) {
log.info("Redis Cluster 集群配置...");
factory = new JedisConnectionFactory(clusterConfiguration, jedisClientConfiguration);
} else {
log.info("Redis Standalone单节点配置...");
RedisStandaloneConfiguration configuration = getRedisStandaloneConfiguration(properties);
factory = new JedisConnectionFactory(configuration, jedisClientConfiguration);
}
return factory;
}
@Bean
public StringRedisTemplate stringRedisTemplate(@Qualifier("redisConnectionFactory") RedisConnectionFactory factory) {
StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
stringRedisTemplate.setConnectionFactory(factory);
return stringRedisTemplate;
}
配置类设置 WxMpService ,注入的是上面Redis配置里的 StringRedisTemplate
@Configuration
public class WechatMpConfig {
@Autowired
private WechatMpProperties wechatMpProperties;
@Autowired
private StringRedisTemplate stringRedisTemplateCustom;
@Bean
public WxMpService wxMpService() {
WxMpService wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
return wxMpService;
}
@Bean
public WxMpConfigStorage wxMpConfigStorage() {
RedisTemplateWxRedisOps wxRedisOps = new RedisTemplateWxRedisOps(stringRedisTemplateCustom);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(wxRedisOps, "wxmp");
wxMpRedisConfig.setAppId(wechatMpProperties.getAppId());
wxMpRedisConfig.setSecret(wechatMpProperties.getAppSecret());
wxMpRedisConfig.setToken(wechatMpProperties.getToken());
wxMpRedisConfig.setAesKey(wechatMpProperties.getAesKey());
return wxMpRedisConfig;
}
}
报错的地方
处理订阅消息获取微信用户信息时:
@Resource
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
WxMpService wxMpService, WxSessionManager sessionManager) {
this.logger.info("新关注用户 OPENID: " + wxMessage.getFromUser());
// 下面方法执行时报错了 Pipeline is currently not supported for JedisClusterConnection
WxMpUser wxMpUser = wechatMpCoreService.getUserInfo(wxMessage.getFromUser(), "zh_CN");
java.lang.UnsupportedOperationException: Pipeline is currently not supported for JedisClusterConnection. at org.springframework.data.redis.connection.jedis.JedisClusterConnection.openPipeline(JedisClusterConnection.java:851) at org.springframework.data.redis.connection.DefaultStringRedisConnection.openPipeline(DefaultStringRedisConnection.java:3973) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.data.redis.core.CloseSuppressingInvocationHandler.invoke(CloseSuppressingInvocationHandler.java:61) at com.sun.proxy.$Proxy372.openPipeline(Unknown Source) at org.springframework.data.redis.core.RedisTemplate.lambda$executePipelined$1(RedisTemplate.java:319) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:223)
在网上搜索,应该是 redis集群客户端JedisCluster不支持Pipeline ,请问有办法处理吗?
你好,我想要使用Redis缓存Access Token,配置和你这个一样,请问一下如果想要缓存Access Token的话,是要单独配置什么吗?因为我直接用下面的代码操作之后再缓存里面没有任何东西
WxOAuth2AccessToken accessToken = wxService.getOAuth2Service().getAccessToken(code);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
登录 后才可以发表评论