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 5f11d315af..329f99e9e8 100644
--- a/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java
+++ b/java/client/src/main/java/glide/api/commands/GenericBaseCommands.java
@@ -24,6 +24,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);
@@ -41,6 +46,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);
@@ -58,6 +68,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);
@@ -76,6 +91,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);
@@ -92,6 +112,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);
@@ -109,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.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry).get()
+ * assert isSet
+ *
*/
CompletableFuture pexpire(String key, long milliseconds, ExpireOptions expireOptions);
@@ -126,6 +156,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);
@@ -144,6 +179,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);
@@ -155,6 +195,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 9f2997fa32..035d0b95eb 100644
--- a/java/client/src/test/java/glide/api/RedisClientTest.java
+++ b/java/client/src/test/java/glide/api/RedisClientTest.java
@@ -217,8 +217,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);
@@ -237,8 +240,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);
@@ -257,8 +263,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);
@@ -277,8 +286,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);
@@ -298,8 +310,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);
@@ -318,8 +333,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);
@@ -339,8 +357,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);
@@ -359,8 +380,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);
@@ -382,6 +406,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);