修复 Spring Boot 3 中 RedisTemplate.getExpire() 兼容性问题#3843
Merged
binarywang merged 3 commits intodevelopfrom Jan 14, 2026
Merged
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix RedisTemplate cache expiration issue
修复 Spring Boot 3 中 RedisTemplate.getExpire() 兼容性问题
Jan 9, 2026
Owner
|
auggie review |
🤖 Augment PR SummarySummary: 修复 Spring Boot 3(Spring Data Redis 3.x)下 🤖 Was this summary useful? React with 👍 or 👎 |
There was a problem hiding this comment.
Pull request overview
这个 PR 修复了 Spring Boot 3 中使用 RedisTemplate 进行配置存储时的缓存失效问题。主要原因是 Spring Data Redis 3.x 改变了 getExpire(K key) 方法的返回值语义:2.x 版本中 key 不存在时返回 null,而 3.x 版本返回 -2。
关键变更
- 将
RedisTemplateWxRedisOps.getExpire()方法中的redisTemplate.getExpire(key)改为redisTemplate.getExpire(key, TimeUnit.SECONDS),确保在两个版本中行为一致 - 新增测试用例
testGetExpireForNonExistentKey()覆盖不存在的 key 场景
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| weixin-java-common/src/main/java/me/chanjar/weixin/common/redis/RedisTemplateWxRedisOps.java | 修改 getExpire 方法实现,使用带 TimeUnit 参数的重载方法确保跨版本兼容性 |
| weixin-java-common/src/test/java/me/chanjar/weixin/common/redis/CommonWxRedisOpsTest.java | 新增测试用例验证不存在的 key 场景下的行为 |
weixin-java-common/src/test/java/me/chanjar/weixin/common/redis/CommonWxRedisOpsTest.java
Outdated
Show resolved
Hide resolved
…s/CommonWxRedisOpsTest.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Spring Data Redis 3.x 改变了
getExpire(K key)的返回值语义:2.x 返回 null 表示 key 不存在,3.x 返回 -2。这导致使用WxOpenInRedisTemplateConfigStorage等 RedisTemplate 配置存储的用户在升级到 Spring Boot 3.x 后缓存失效。修改内容
getExpire(key, TimeUnit.SECONDS)替代getExpire(key),该重载方法在两个版本中行为一致testGetExpireForNonExistentKey()覆盖不存在 key 的场景此修改向后兼容 Spring Data Redis 2.x,同时修复 3.x 的兼容性问题。
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.