mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-01-23 13:22:04 +08:00
🎨 #3843 【基础架构】修复 Spring Boot 3(Spring Data Redis 3.x)下 RedisTemplate.getExpire 返回值语义变化导致的过期判断/缓存失效问题
This commit is contained in:
@@ -29,7 +29,7 @@ public class RedisTemplateWxRedisOps implements WxRedisOps {
|
||||
|
||||
@Override
|
||||
public Long getExpire(String key) {
|
||||
return redisTemplate.getExpire(key);
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,17 @@ public class CommonWxRedisOpsTest {
|
||||
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpireForNonExistentKey() {
|
||||
String nonExistentKey = "non_existent_key_" + System.currentTimeMillis();
|
||||
Long expire = wxRedisOps.getExpire(nonExistentKey);
|
||||
// 对于不存在的 key,底层使用 getExpire(key, TimeUnit.SECONDS) 时应返回负值
|
||||
// Spring Data Redis 2.x 和 3.x 约定:-2 表示 key 不存在,-1 表示 key 没有过期时间
|
||||
// 因此这里不应返回 null,而应返回一个小于 0 的值
|
||||
Assert.assertNotNull(expire, "Non-existent key should not have null expiration");
|
||||
Assert.assertTrue(expire < 0, "Non-existent key should have negative expiration");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpire() {
|
||||
String key = "access_token", value = String.valueOf(System.currentTimeMillis());
|
||||
|
||||
Reference in New Issue
Block a user