修改 Redis 配置实现类以实现选择数据库及密码认证功能#1314
Merged
binarywang merged 1 commit intobinarywang:developfrom Dec 8, 2019
Merged
Conversation
Author
|
另外修改的时候发现了 #1313 ,不知是依赖不对还是分支没开发完成 |
yuanqixun
pushed a commit
to yuanqixun/weixin-java-tools
that referenced
this pull request
Dec 9, 2019
…-tools into develop * 'develop' of https://github.com/Wechat-Group/weixin-java-tools: 🎨 优化重构微信小程序订阅消息相关类 🎨 binarywang#1314 优化增强微信小程序Redis配置实现类功能 ✨ binarywang#1309 增加发送和查询企业微信红包的接口 🔖 发布3.6.1.B测试版本 ✨ binarywang#1033 微信支付增加发送小程序红包的接口 Update README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
主要是将
cn.binarywang.wx.miniapp.config.impl.WxMaRedisConfigImpl重命名为AbstractWxMaRedisConfig,在保留原来的 Redis 存储逻辑下,抽象了一个getJedis()方法出来,用于从子类获得 Jedis 实例:https://github.com/xJoeWoo/WxJava/blob/e29680928023a5f92491fd5a2a0beebf42b216d8/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java#L53
并且在
AbstractWxMaRedisConfig类中添加了一个回调接口JedisConfig,用于配置每次操作的 Jedis 实例:https://github.com/xJoeWoo/WxJava/blob/e29680928023a5f92491fd5a2a0beebf42b216d8/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java#L18-L20
在调用
setJedisConfig设置回调后,可以在回调接口实现中,进行select()选择数据库,或auth()进行密码认证等配置操作:其它改进:
AbstractWxMaRedisConfig修改成继承WxMaDefaultConfigImplWxMaDefaultConfigImpl.expiresAheadInMillis方法,用于统一修改提前过期时间https://github.com/xJoeWoo/WxJava/blob/e29680928023a5f92491fd5a2a0beebf42b216d8/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java#L51-L56
WxMaDefaultConfigImpl.isExpired方法,用于统一判断传入时间是否过期https://github.com/xJoeWoo/WxJava/blob/e29680928023a5f92491fd5a2a0beebf42b216d8/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java#L58-L63
AbstractWxMaRedisConfig.redisKeyPrefix字段,用于修改存放配置参数的 Redis Keyhttps://github.com/xJoeWoo/WxJava/blob/e29680928023a5f92491fd5a2a0beebf42b216d8/weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/AbstractWxMaRedisConfig.java#L29-L32
WxMaRedisConfigImpl添加了传入 JedisPool 的构造方法,同时将无参构造函数和setJedisPool置为过时。因为此配置类必须依赖 JedisPool,适合从构造方法传入,否则容易忽略调用setJedisPool设置 JedisPool。若此方案可行,这里可以一并修改其它项目的 Redis 配置类。