diff --git a/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java b/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java index 52013feb40..2ae9cc3333 100644 --- a/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java +++ b/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java @@ -67,6 +67,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.expire("my_key", 60).get()
+     * assert isSet //Indicates that a timeout of 60 seconds has been set for "my_key."
+     * 
*/ CompletableFuture expire(String key, long seconds); @@ -84,6 +89,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.expire("my_key", 60, ExpireOptions.HAS_NO_EXPIRY).get()
+     * assert isSet //Indicates that a timeout of 60 seconds has been set for "my_key."
+     * 
*/ CompletableFuture expire(String key, long seconds, ExpireOptions expireOptions); @@ -101,6 +111,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.expireAt("my_key", 1672531200).get()
+     * assert isSet
+     * 
*/ CompletableFuture expireAt(String key, long unixSeconds); @@ -119,6 +134,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.expireAt("my_key", 1672531200, ExpireOptions.HasNoExpiry).get()
+     * assert isSet
+     * 
*/ CompletableFuture expireAt(String key, long unixSeconds, ExpireOptions expireOptions); @@ -135,6 +155,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.pexpire("my_key", 60000).get()
+     * assert isSet
+     * 
*/ CompletableFuture pexpire(String key, long milliseconds); @@ -152,6 +177,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry).get()
+     * assert isSet
+     * 
*/ CompletableFuture pexpire(String key, long milliseconds, ExpireOptions expireOptions); @@ -169,6 +199,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.pexpireAt("my_key", 1672531200000).get()
+     * assert isSet
+     * 
*/ CompletableFuture pexpireAt(String key, long unixMilliseconds); @@ -187,6 +222,11 @@ public interface GenericBaseCommands { * @return true if the timeout was set. false if the timeout was not * set. e.g. key doesn't exist, or operation skipped due to the provided * arguments. + * @example + *
+     * Boolean isSet = client.pexpireAt("my_key", 1672531200000, ExpireOptions.HasNoExpiry).get()
+     * assert isSet
+     * 
*/ CompletableFuture pexpireAt( String key, long unixMilliseconds, ExpireOptions expireOptions); @@ -198,6 +238,13 @@ CompletableFuture pexpireAt( * @param key The key to return its timeout. * @return TTL in seconds, -2 if key does not exist, or -1 if key exists * but has no associated expire. + * @example + *
+     * Long timeRemaining = client.ttl("my_key").get()
+     * assert timeRemaining == 3600L //Indicates that "my_key" has a remaining time to live of 3600 seconds.
+     * Long timeRemaining = client.ttl("nonexistent_key").get()
+     * assert timeRemaining == -2L //Returns -2 for a non-existing key.
+     * 
*/ CompletableFuture ttl(String key); } diff --git a/java/client/src/test/java/glide/api/RedisClientTest.java b/java/client/src/test/java/glide/api/RedisClientTest.java index 2d65f7aa95..78da6e9204 100644 --- a/java/client/src/test/java/glide/api/RedisClientTest.java +++ b/java/client/src/test/java/glide/api/RedisClientTest.java @@ -306,8 +306,11 @@ public void expire_returns_success() { String key = "testKey"; long seconds = 10L; String[] arguments = new String[] {key, Long.toString(seconds)}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(true); + + // match on protobuf request when(commandManager.submitNewCommand(eq(Expire), eq(arguments), any())) .thenReturn(testResponse); @@ -326,8 +329,11 @@ public void expire_with_expireOptions_returns_success() { String key = "testKey"; long seconds = 10L; String[] arguments = new String[] {key, Long.toString(seconds), "NX"}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(false); + + // match on protobuf request when(commandManager.submitNewCommand(eq(Expire), eq(arguments), any())) .thenReturn(testResponse); @@ -346,8 +352,11 @@ public void expireAt_returns_success() { String key = "testKey"; long unixSeconds = 100000L; String[] arguments = new String[] {key, Long.toString(unixSeconds)}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(true); + + // match on protobuf request when(commandManager.submitNewCommand(eq(ExpireAt), eq(arguments), any())) .thenReturn(testResponse); @@ -366,8 +375,11 @@ public void expireAt_with_expireOptions_returns_success() { String key = "testKey"; long unixSeconds = 100000L; String[] arguments = new String[] {key, Long.toString(unixSeconds), "XX"}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(false); + + // match on protobuf request when(commandManager.submitNewCommand(eq(ExpireAt), eq(arguments), any())) .thenReturn(testResponse); @@ -387,8 +399,11 @@ public void pexpire_returns_success() { String key = "testKey"; long milliseconds = 5L; String[] arguments = new String[] {key, Long.toString(milliseconds)}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(true); + + // match on protobuf request when(commandManager.submitNewCommand(eq(PExpire), eq(arguments), any())) .thenReturn(testResponse); @@ -407,8 +422,11 @@ public void pexpire_with_expireOptions_returns_success() { String key = "testKey"; long milliseconds = 5L; String[] arguments = new String[] {key, Long.toString(milliseconds), "LT"}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(false); + + // match on protobuf request when(commandManager.submitNewCommand(eq(PExpire), eq(arguments), any())) .thenReturn(testResponse); @@ -428,8 +446,11 @@ public void pexpireAt_returns_success() { String key = "testKey"; long unixMilliseconds = 999999L; String[] arguments = new String[] {key, Long.toString(unixMilliseconds)}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(true); + + // match on protobuf request when(commandManager.submitNewCommand(eq(PExpireAt), eq(arguments), any())) .thenReturn(testResponse); @@ -448,8 +469,11 @@ public void pexpireAt_with_expireOptions_returns_success() { String key = "testKey"; long unixMilliseconds = 999999L; String[] arguments = new String[] {key, Long.toString(unixMilliseconds), "GT"}; + CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(false); + + // match on protobuf request when(commandManager.submitNewCommand(eq(PExpireAt), eq(arguments), any())) .thenReturn(testResponse); @@ -471,6 +495,8 @@ public void ttl_returns_success() { CompletableFuture testResponse = mock(CompletableFuture.class); when(testResponse.get()).thenReturn(ttl); + + // match on protobuf request when(commandManager.submitNewCommand(eq(TTL), eq(new String[] {key}), any())) .thenReturn(testResponse);