DATAREDIS-526 - Fix getExpire return value.

getExpire returns now negative values without time unit conversion in case of absent values or values without a TTL set.

CLA: 143520151016081625 (Duobiao Ou)
Original pull request: #205.
This commit is contained in:
oudb
2016-06-23 17:13:28 +08:00
committed by Mark Paluch
parent f5a506cb8d
commit e64f84b45a
2 changed files with 38 additions and 2 deletions

View File

@@ -715,11 +715,14 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
return execute(new RedisCallback<Long>() {
public Long doInRedis(RedisConnection connection) {
Long expire;
try {
return timeUnit.convert(connection.pTtl(rawKey), TimeUnit.MILLISECONDS);
expire = connection.pTtl(rawKey);
return expire < 0 ? expire : timeUnit.convert(expire, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// Driver may not support pTtl or we may be running on Redis 2.4
return timeUnit.convert(connection.ttl(rawKey), TimeUnit.SECONDS);
expire = connection.ttl(rawKey);
return expire < 0 ? expire : timeUnit.convert(expire, TimeUnit.SECONDS);
}
}
}, true);