Skip to content

Commit

Permalink
GEODE-8629: Redis TTL should round up the returned value (apache#5640)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeppe-pivotal authored Oct 21, 2020
1 parent 7a0fd2e commit b76eba7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

package org.apache.geode.redis.internal.executor.key;

import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -73,6 +76,16 @@ public void shouldReturnCorrectExpiration_givenKeyHasExpirationSet() {
jedis.set("orange", "crush");
jedis.expire("orange", 20);

assertThat(jedis.ttl("orange")).isGreaterThan(15);
assertThat(jedis.ttl("orange")).isEqualTo(20);
}

@Test
public void shouldSeeTTLdecreasing() {
jedis.set("orange", "crush");
jedis.expire("orange", 20);

await("TTL should decrease").atMost(2, TimeUnit.SECONDS)
.until(() -> jedis.ttl("orange") < 20);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public RedisResponse executeCommand(Command command,
RedisKeyCommands redisKeyCommands = getRedisKeyCommands(context);
long result = redisKeyCommands.pttl(key);
if (result > 0 && !timeUnitMillis()) {
result = MILLISECONDS.toSeconds(result);
// Round up because redis does
result = MILLISECONDS.toSeconds(result + 500);
}

return RedisResponse.integer(result);
Expand Down

0 comments on commit b76eba7

Please sign in to comment.