Skip to content
Merged
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,17 @@ 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);
// 对于不存在的 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());
Expand Down