Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void setValue(String key, String value, int expire, TimeUnit timeUnit) {

@Override
public Long getExpire(String key) {
return redisTemplate.getExpire(key);
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public void testGetExpire() {
Assert.assertTrue(expireSeconds <= 4 && expireSeconds >= 0);
}

@Test
public void testGetExpireForNonExistentKey() {
String nonExistentKey = "non_existent_key_" + System.currentTimeMillis();
Long expire = wxRedisOps.getExpire(nonExistentKey);
// For non-existent keys, getExpire should return a negative value
// In Spring Data Redis 2.x: may return null (but our implementation should handle this)
// In Spring Data Redis 3.x: returns -2
Assert.assertTrue(expire == null || expire < 0, "Non-existent key should have null or negative expiration");
Comment on lines +42 to +45
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释表明 Spring Data Redis 2.x 可能返回 null,但使用 getExpire(key, TimeUnit.SECONDS) 方法后,该方法在 Spring Data Redis 2.x 和 3.x 中都不应该返回 null,而是返回 -2 表示 key 不存在,-1 表示 key 没有过期时间。建议更新注释以反映实际行为,或者移除对 null 的检查。

Suggested change
// For non-existent keys, getExpire should return a negative value
// In Spring Data Redis 2.x: may return null (but our implementation should handle this)
// In Spring Data Redis 3.x: returns -2
Assert.assertTrue(expire == null || expire < 0, "Non-existent key should have null or negative expiration");
// 对于不存在的 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");

Copilot uses AI. Check for mistakes.
}

@Test
public void testExpire() {
String key = "access_token", value = String.valueOf(System.currentTimeMillis());
Expand Down
Loading