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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user