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
修改成继承WxMaDefaultConfigImpl
WxMaDefaultConfigImpl.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 配置类。