Package glide.api.commands
Interface GenericBaseCommands
-
- All Known Implementing Classes:
BaseClient,GlideClient,GlideClusterClient
public interface GenericBaseCommandsSupports commands for the "Generic Commands" group for standalone and cluster clients.- See Also:
- Generic Commands
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDB_VALKEY_APIValkey API keyword used to denote the destination db index.static java.lang.StringREPLACE_VALKEY_APIValkey API keyword used to replace the destination key.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(GlideString source, GlideString destination)Copies the value stored at thesourceto thedestinationkey if thedestinationkey does not yet exist.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(GlideString source, GlideString destination, boolean replace)Copies the value stored at thesourceto thedestinationkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(GlideString source, GlideString destination, long destinationDB)Copies the value stored at thesourceto thedestinationkey ondestinationDB.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(GlideString source, GlideString destination, long destinationDB, boolean replace)Copies the value stored at thesourceto thedestinationkey ondestinationDB.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(java.lang.String source, java.lang.String destination)Copies the value stored at thesourceto thedestinationkey if thedestinationkey does not yet exist.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(java.lang.String source, java.lang.String destination, boolean replace)Copies the value stored at thesourceto thedestinationkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(java.lang.String source, java.lang.String destination, long destinationDB)Copies the value stored at thesourceto thedestinationkey ondestinationDB.java.util.concurrent.CompletableFuture<java.lang.Boolean>copy(java.lang.String source, java.lang.String destination, long destinationDB, boolean replace)Copies the value stored at thesourceto thedestinationkey ondestinationDB.java.util.concurrent.CompletableFuture<java.lang.Long>del(GlideString[] keys)Removes the specifiedkeysfrom the database.java.util.concurrent.CompletableFuture<java.lang.Long>del(java.lang.String[] keys)Removes the specifiedkeysfrom the database.java.util.concurrent.CompletableFuture<byte[]>dump(GlideString key)Serialize the value stored atkeyin a Valkey-specific format and return it to the user.java.util.concurrent.CompletableFuture<java.lang.Long>exists(GlideString[] keys)Returns the number of keys inkeysthat exist in the database.java.util.concurrent.CompletableFuture<java.lang.Long>exists(java.lang.String[] keys)Returns the number of keys inkeysthat exist in the database.java.util.concurrent.CompletableFuture<java.lang.Boolean>expire(GlideString key, long seconds)Sets a timeout onkeyin seconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>expire(GlideString key, long seconds, ExpireOptions expireOptions)Sets a timeout onkeyin seconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>expire(java.lang.String key, long seconds)Sets a timeout onkeyin seconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>expire(java.lang.String key, long seconds, ExpireOptions expireOptions)Sets a timeout onkeyin seconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>expireAt(GlideString key, long unixSeconds)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>expireAt(GlideString key, long unixSeconds, ExpireOptions expireOptions)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>expireAt(java.lang.String key, long unixSeconds)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>expireAt(java.lang.String key, long unixSeconds, ExpireOptions expireOptions)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Long>expiretime(GlideString key)Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in seconds.
To get the expiration with millisecond precision, usepexpiretime(String).java.util.concurrent.CompletableFuture<java.lang.Long>expiretime(java.lang.String key)Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in seconds.
To get the expiration with millisecond precision, usepexpiretime(String).java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, GlideString key, long destinationDB, long timeout)Atomically transfers a key from a source Valkey instance to a destination Valkey instance.java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, GlideString key, long destinationDB, long timeout, MigrateOptions migrateOptions)Atomically transfers a key from a source Valkey instance to a destination Valkey instance.java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, java.lang.String key, long destinationDB, long timeout)Atomically transfers a key from a source Valkey instance to a destination Valkey instance.java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, java.lang.String key, long destinationDB, long timeout, MigrateOptions migrateOptions)Atomically transfers a key from a source Valkey instance to a destination Valkey instance.java.util.concurrent.CompletableFuture<java.lang.Boolean>move(GlideString key, long dbIndex)Movekeyfrom the currently selected database to the database specified bydbIndex.java.util.concurrent.CompletableFuture<java.lang.Boolean>move(java.lang.String key, long dbIndex)Movekeyfrom the currently selected database to the database specified bydbIndex.java.util.concurrent.CompletableFuture<java.lang.String>objectEncoding(GlideString key)Returns the internal encoding for the Valkey object stored atkey.java.util.concurrent.CompletableFuture<java.lang.String>objectEncoding(java.lang.String key)Returns the internal encoding for the Valkey object stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectFreq(GlideString key)Returns the logarithmic access frequency counter of a Valkey object stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectFreq(java.lang.String key)Returns the logarithmic access frequency counter of a Valkey object stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectIdletime(GlideString key)Returns the time in seconds since the last access to the value stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectIdletime(java.lang.String key)Returns the time in seconds since the last access to the value stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectRefcount(GlideString key)Returns the reference count of the object stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>objectRefcount(java.lang.String key)Returns the reference count of the object stored atkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>persist(GlideString key)Removes the existing timeout onkey, turning thekeyfrom volatile (akeywith an expire set) to persistent (akeythat will never expire as no timeout is associated).java.util.concurrent.CompletableFuture<java.lang.Boolean>persist(java.lang.String key)Removes the existing timeout onkey, turning thekeyfrom volatile (akeywith an expire set) to persistent (akeythat will never expire as no timeout is associated).java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpire(GlideString key, long milliseconds)Sets a timeout onkeyin milliseconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpire(GlideString key, long milliseconds, ExpireOptions expireOptions)Sets a timeout onkeyin milliseconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpire(java.lang.String key, long milliseconds)Sets a timeout onkeyin milliseconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpire(java.lang.String key, long milliseconds, ExpireOptions expireOptions)Sets a timeout onkeyin milliseconds.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpireAt(GlideString key, long unixMilliseconds)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpireAt(GlideString key, long unixMilliseconds, ExpireOptions expireOptions)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpireAt(java.lang.String key, long unixMilliseconds)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Boolean>pexpireAt(java.lang.String key, long unixMilliseconds, ExpireOptions expireOptions)Sets a timeout onkey.java.util.concurrent.CompletableFuture<java.lang.Long>pexpiretime(GlideString key)Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in milliseconds.java.util.concurrent.CompletableFuture<java.lang.Long>pexpiretime(java.lang.String key)Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in milliseconds.java.util.concurrent.CompletableFuture<java.lang.Long>pttl(GlideString key)Returns the remaining time to live ofkeythat has a timeout, in milliseconds.java.util.concurrent.CompletableFuture<java.lang.Long>pttl(java.lang.String key)Returns the remaining time to live ofkeythat has a timeout, in milliseconds.java.util.concurrent.CompletableFuture<java.lang.String>rename(GlideString key, GlideString newKey)RenameskeytonewKey.
IfnewKeyalready exists it is overwritten.java.util.concurrent.CompletableFuture<java.lang.String>rename(java.lang.String key, java.lang.String newKey)RenameskeytonewKey.
IfnewKeyalready exists it is overwritten.java.util.concurrent.CompletableFuture<java.lang.Boolean>renamenx(GlideString key, GlideString newKey)RenameskeytonewKeyifnewKeydoes not yet exist.java.util.concurrent.CompletableFuture<java.lang.Boolean>renamenx(java.lang.String key, java.lang.String newKey)RenameskeytonewKeyifnewKeydoes not yet exist.java.util.concurrent.CompletableFuture<java.lang.String>restore(GlideString key, long ttl, byte[] value)Create akeyassociated with avaluethat is obtained by deserializing the provided serializedvalue(obtained viadump(glide.api.models.GlideString)).java.util.concurrent.CompletableFuture<java.lang.String>restore(GlideString key, long ttl, byte[] value, RestoreOptions restoreOptions)Create akeyassociated with avaluethat is obtained by deserializing the provided serializedvalue(obtained viadump(glide.api.models.GlideString)).java.util.concurrent.CompletableFuture<GlideString[]>sort(GlideString key)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<GlideString[]>sort(GlideString key, SortOptionsBinary sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<java.lang.String[]>sort(java.lang.String key)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<java.lang.String[]>sort(java.lang.String key, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<GlideString[]>sortReadOnly(GlideString key)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<GlideString[]>sortReadOnly(GlideString key, SortOptionsBinary sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<java.lang.String[]>sortReadOnly(java.lang.String key)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<java.lang.String[]>sortReadOnly(java.lang.String key, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result.java.util.concurrent.CompletableFuture<java.lang.Long>sortStore(GlideString key, GlideString destination)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination.java.util.concurrent.CompletableFuture<java.lang.Long>sortStore(GlideString key, GlideString destination, SortOptionsBinary sortOptions)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination.java.util.concurrent.CompletableFuture<java.lang.Long>sortStore(java.lang.String key, java.lang.String destination)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination.java.util.concurrent.CompletableFuture<java.lang.Long>sortStore(java.lang.String key, java.lang.String destination, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination.java.util.concurrent.CompletableFuture<java.lang.Long>touch(GlideString[] keys)Updates the last access time of specifiedkeys.java.util.concurrent.CompletableFuture<java.lang.Long>touch(java.lang.String[] keys)Updates the last access time of specifiedkeys.java.util.concurrent.CompletableFuture<java.lang.Long>ttl(GlideString key)Returns the remaining time to live ofkeythat has a timeout, in seconds.java.util.concurrent.CompletableFuture<java.lang.Long>ttl(java.lang.String key)Returns the remaining time to live ofkeythat has a timeout, in seconds.java.util.concurrent.CompletableFuture<java.lang.String>type(GlideString key)Returns the string representation of the type of the value stored atkey.java.util.concurrent.CompletableFuture<java.lang.String>type(java.lang.String key)Returns the string representation of the type of the value stored atkey.java.util.concurrent.CompletableFuture<java.lang.Long>unlink(GlideString[] keys)Unlink (delete) multiplekeysfrom the database.java.util.concurrent.CompletableFuture<java.lang.Long>unlink(java.lang.String[] keys)Unlink (delete) multiplekeysfrom the database.java.util.concurrent.CompletableFuture<java.lang.Long>wait(long numreplicas, long timeout)Blocks the current client until all the previous write commands are successfully transferred and acknowledged by at leastnumreplicasof replicas.java.util.concurrent.CompletableFuture<java.lang.Long[]>waitaof(long numlocal, long numreplicas, long timeout)Blocks the current client until all previous write commands are successfully transferred and acknowledged by at leastnumlocalandnumreplicasof replicas.
-
-
-
Field Detail
-
REPLACE_VALKEY_API
static final java.lang.String REPLACE_VALKEY_API
Valkey API keyword used to replace the destination key.- See Also:
- Constant Field Values
-
DB_VALKEY_API
static final java.lang.String DB_VALKEY_API
Valkey API keyword used to denote the destination db index.- See Also:
- Constant Field Values
-
-
Method Detail
-
del
java.util.concurrent.CompletableFuture<java.lang.Long> del(java.lang.String[] keys)
Removes the specifiedkeysfrom the database. A key is ignored if it does not exist.- Parameters:
keys- The keys we wanted to remove.- Returns:
- The number of keys that were removed.
- See Also:
- valkey.io for details.
- Example:
Long num = client.del(new String[] {"key1", "key2"}).get(); assert num == 2L;
-
del
java.util.concurrent.CompletableFuture<java.lang.Long> del(GlideString[] keys)
Removes the specifiedkeysfrom the database. A key is ignored if it does not exist.- Parameters:
keys- The keys we wanted to remove.- Returns:
- The number of keys that were removed.
- See Also:
- valkey.io for details.
- Example:
Long num = client.del(new GlideString[] {gs("key1"), gs("key2")}).get(); assert num == 2L;
-
exists
java.util.concurrent.CompletableFuture<java.lang.Long> exists(java.lang.String[] keys)
Returns the number of keys inkeysthat exist in the database.- Parameters:
keys- The keys list to check.- Returns:
- The number of keys that exist. If the same existing key is mentioned in
keysmultiple times, it will be counted multiple times. - See Also:
- valkey.io for details.
- Example:
Long result = client.exists(new String[] {"my_key", "invalid_key"}).get(); assert result == 1L;
-
exists
java.util.concurrent.CompletableFuture<java.lang.Long> exists(GlideString[] keys)
Returns the number of keys inkeysthat exist in the database.- Parameters:
keys- The keys list to check.- Returns:
- The number of keys that exist. If the same existing key is mentioned in
keysmultiple times, it will be counted multiple times. - See Also:
- valkey.io for details.
- Example:
Long result = client.exists(new GlideString[] {gs("my_key"), gs("invalid_key")}).get(); assert result == 1L;
-
unlink
java.util.concurrent.CompletableFuture<java.lang.Long> unlink(java.lang.String[] keys)
Unlink (delete) multiplekeysfrom the database. A key is ignored if it does not exist. This command, similar to DEL, removes specified keys and ignores non-existent ones. However, this command does not block the server, while DEL does.- Parameters:
keys- The list of keys to unlink.- Returns:
- The number of
keysthat were unlinked. - See Also:
- valkey.io for details.
- Example:
Long result = client.unlink(new String[] {"my_key"}).get(); assert result == 1L;
-
unlink
java.util.concurrent.CompletableFuture<java.lang.Long> unlink(GlideString[] keys)
Unlink (delete) multiplekeysfrom the database. A key is ignored if it does not exist. This command, similar to DEL, removes specified keys and ignores non-existent ones. However, this command does not block the server, while DEL does.- Parameters:
keys- The list of keys to unlink.- Returns:
- The number of
keysthat were unlinked. - See Also:
- valkey.io for details.
- Example:
Long result = client.unlink(new GlideString[] {gs("my_key")}).get(); assert result == 1L;
-
expire
java.util.concurrent.CompletableFuture<java.lang.Boolean> expire(java.lang.String key, long seconds)Sets a timeout onkeyin seconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifsecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.seconds- The timeout in seconds.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expire("my_key", 60).get(); assert isSet; //Indicates that a timeout of 60 seconds has been set for "my_key."
-
expire
java.util.concurrent.CompletableFuture<java.lang.Boolean> expire(GlideString key, long seconds)
Sets a timeout onkeyin seconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifsecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.seconds- The timeout in seconds.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expire(gs("my_key"), 60).get(); assert isSet; //Indicates that a timeout of 60 seconds has been set for gs("my_key").
-
expire
java.util.concurrent.CompletableFuture<java.lang.Boolean> expire(java.lang.String key, long seconds, ExpireOptions expireOptions)Sets a timeout onkeyin seconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifsecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.seconds- The timeout in seconds.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- 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".
-
expire
java.util.concurrent.CompletableFuture<java.lang.Boolean> expire(GlideString key, long seconds, ExpireOptions expireOptions)
Sets a timeout onkeyin seconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifsecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.seconds- The timeout in seconds.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expire(gs("my_key"), 60, ExpireOptions.HAS_NO_EXPIRY).get(); assert isSet; //Indicates that a timeout of 60 seconds has been set for gs("my_key").
-
expireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> expireAt(java.lang.String key, long unixSeconds)Sets a timeout onkey. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.unixSeconds- The timeout in an absolute Unix timestamp.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expireAt("my_key", Instant.now().getEpochSecond() + 10).get(); assert isSet;
-
expireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> expireAt(GlideString key, long unixSeconds)
Sets a timeout onkey. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.unixSeconds- The timeout in an absolute Unix timestamp.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expireAt(gs("my_key"), Instant.now().getEpochSecond() + 10).get(); assert isSet;
-
expireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> expireAt(java.lang.String key, long unixSeconds, ExpireOptions expireOptions)Sets a timeout onkey. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.unixSeconds- The timeout in an absolute Unix timestamp.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expireAt("my_key", Instant.now().getEpochSecond() + 10, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
expireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> expireAt(GlideString key, long unixSeconds, ExpireOptions expireOptions)
Sets a timeout onkey. It takes an absolute Unix timestamp (seconds since January 1, 1970) instead of specifying the number of seconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.unixSeconds- The timeout in an absolute Unix timestamp.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.expireAt(gs("my_key"), Instant.now().getEpochSecond() + 10, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
pexpire
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpire(java.lang.String key, long milliseconds)Sets a timeout onkeyin milliseconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifmillisecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.milliseconds- The timeout in milliseconds.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpire("my_key", 60000).get(); assert isSet;
-
pexpire
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpire(GlideString key, long milliseconds)
Sets a timeout onkeyin milliseconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
Ifmillisecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.milliseconds- The timeout in milliseconds.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpire(gs("my_key"), 60000).get(); assert isSet;
-
pexpire
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpire(java.lang.String key, long milliseconds, ExpireOptions expireOptions)Sets a timeout onkeyin milliseconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existing expire set, the time to live is updated to the new value.
Ifmillisecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.milliseconds- The timeout in milliseconds.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpire("my_key", 60000, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
pexpire
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpire(GlideString key, long milliseconds, ExpireOptions expireOptions)
Sets a timeout onkeyin milliseconds. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existing expire set, the time to live is updated to the new value.
Ifmillisecondsis a non-positive number, thekeywill be deleted rather than expired.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- The key to set timeout on it.milliseconds- The timeout in milliseconds.expireOptions- The expire options.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpire(gs("my_key"), 60000, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
pexpireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpireAt(java.lang.String key, long unixMilliseconds)Sets a timeout onkey. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- Thekeyto set timeout on it.unixMilliseconds- The timeout in an absolute Unix timestamp.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpireAt("my_key", Instant.now().toEpochMilli() + 10).get(); assert isSet;
-
pexpireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpireAt(GlideString key, long unixMilliseconds)
Sets a timeout onkey. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- Thekeyto set timeout on it.unixMilliseconds- The timeout in an absolute Unix timestamp.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpireAt(gs("my_key"), Instant.now().toEpochMilli() + 10).get(); assert isSet;
-
pexpireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpireAt(java.lang.String key, long unixMilliseconds, ExpireOptions expireOptions)Sets a timeout onkey. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- Thekeyto set timeout on it.unixMilliseconds- The timeout in an absolute Unix timestamp.expireOptions- The expire option.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpireAt("my_key", Instant.now().toEpochMilli() + 10, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
pexpireAt
java.util.concurrent.CompletableFuture<java.lang.Boolean> pexpireAt(GlideString key, long unixMilliseconds, ExpireOptions expireOptions)
Sets a timeout onkey. It takes an absolute Unix timestamp (milliseconds since January 1, 1970) instead of specifying the number of milliseconds.
A timestamp in the past will delete thekeyimmediately. After the timeout has expired, thekeywill automatically be deleted.
Ifkeyalready has an existingexpireset, the time to live is updated to the new value.
The timeout will only be cleared by commands that delete or overwrite the contents ofkey.- Parameters:
key- Thekeyto set timeout on it.unixMilliseconds- The timeout in an absolute Unix timestamp.expireOptions- The expire option.- Returns:
trueif the timeout was set.falseif the timeout was not set. e.g.keydoesn't exist, or operation skipped due to the provided arguments.- See Also:
- valkey.io for details.
- Example:
Boolean isSet = client.pexpireAt(gs("my_key"), Instant.now().toEpochMilli() + 10, ExpireOptions.HasNoExpiry).get(); assert isSet;
-
ttl
java.util.concurrent.CompletableFuture<java.lang.Long> ttl(java.lang.String key)
Returns the remaining time to live ofkeythat has a timeout, in seconds.- Parameters:
key- Thekeyto return its timeout.- Returns:
- TTL in seconds,
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - See Also:
- valkey.io for details.
- 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.
-
ttl
java.util.concurrent.CompletableFuture<java.lang.Long> ttl(GlideString key)
Returns the remaining time to live ofkeythat has a timeout, in seconds.- Parameters:
key- Thekeyto return its timeout.- Returns:
- TTL in seconds,
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - See Also:
- valkey.io for details.
- Example:
Long timeRemaining = client.ttl(gs("my_key")).get(); assert timeRemaining == 3600L; //Indicates that gs("my_key") has a remaining time to live of 3600 seconds. Long timeRemaining = client.ttl(gs("nonexistent_key")).get(); assert timeRemaining == -2L; //Returns -2 for a non-existing key.
-
expiretime
java.util.concurrent.CompletableFuture<java.lang.Long> expiretime(java.lang.String key)
Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in seconds.
To get the expiration with millisecond precision, usepexpiretime(String).- Parameters:
key- Thekeyto determine the expiration value of.- Returns:
- The expiration Unix timestamp in seconds.
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long expiration = client.expiretime("my_key").get(); System.out.printf("The key expires at %d epoch time", expiration);
-
expiretime
java.util.concurrent.CompletableFuture<java.lang.Long> expiretime(GlideString key)
Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in seconds.
To get the expiration with millisecond precision, usepexpiretime(String).- Parameters:
key- Thekeyto determine the expiration value of.- Returns:
- The expiration Unix timestamp in seconds.
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long expiration = client.expiretime(gs("my_key")).get(); System.out.printf("The key expires at %d epoch time", expiration);
-
pexpiretime
java.util.concurrent.CompletableFuture<java.lang.Long> pexpiretime(java.lang.String key)
Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in milliseconds.- Parameters:
key- Thekeyto determine the expiration value of.- Returns:
- The expiration Unix timestamp in milliseconds.
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long expiration = client.pexpiretime("my_key").get(); System.out.printf("The key expires at %d epoch time (ms)", expiration);
-
pexpiretime
java.util.concurrent.CompletableFuture<java.lang.Long> pexpiretime(GlideString key)
Returns the absolute Unix timestamp (since January 1, 1970) at which the givenkeywill expire, in milliseconds.- Parameters:
key- Thekeyto determine the expiration value of.- Returns:
- The expiration Unix timestamp in milliseconds.
-2ifkeydoes not exist, or-1ifkeyexists but has no associated expiration. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
Long expiration = client.pexpiretime(gs("my_key")).get(); System.out.printf("The key expires at %d epoch time (ms)", expiration);
-
pttl
java.util.concurrent.CompletableFuture<java.lang.Long> pttl(java.lang.String key)
Returns the remaining time to live ofkeythat has a timeout, in milliseconds.- Parameters:
key- The key to return its timeout.- Returns:
- TTL in milliseconds.
-2ifkeydoes not exist,-1ifkeyexists but has no associated expire. - See Also:
- valkey.io for details.
- Example:
Long timeRemainingMS = client.pttl("my_key").get() assert timeRemainingMS == 5000L // Indicates that "my_key" has a remaining time to live of 5000 milliseconds. Long timeRemainingMS = client.pttl("nonexistent_key").get(); assert timeRemainingMS == -2L; // Returns -2 for a non-existing key.
-
pttl
java.util.concurrent.CompletableFuture<java.lang.Long> pttl(GlideString key)
Returns the remaining time to live ofkeythat has a timeout, in milliseconds.- Parameters:
key- The key to return its timeout.- Returns:
- TTL in milliseconds.
-2ifkeydoes not exist,-1ifkeyexists but has no associated expire. - See Also:
- valkey.io for details.
- Example:
Long timeRemainingMS = client.pttl(gs("my_key")).get() assert timeRemainingMS == 5000L // Indicates that gs("my_key") has a remaining time to live of 5000 milliseconds. Long timeRemainingMS = client.pttl(gs("nonexistent_key")).get(); assert timeRemainingMS == -2L; // Returns -2 for a non-existing key.
-
persist
java.util.concurrent.CompletableFuture<java.lang.Boolean> persist(java.lang.String key)
Removes the existing timeout onkey, turning thekeyfrom volatile (akeywith an expire set) to persistent (akeythat will never expire as no timeout is associated).- Parameters:
key- Thekeyto remove the existing timeout on.- Returns:
falseifkeydoes not exist or does not have an associated timeout,trueif the timeout has been removed.- See Also:
- valkey.io for details.
- Example:
Boolean timeoutRemoved = client.persist("my_key").get(); assert timeoutRemoved; // Indicates that the timeout associated with the key "my_key" was successfully removed.
-
persist
java.util.concurrent.CompletableFuture<java.lang.Boolean> persist(GlideString key)
Removes the existing timeout onkey, turning thekeyfrom volatile (akeywith an expire set) to persistent (akeythat will never expire as no timeout is associated).- Parameters:
key- Thekeyto remove the existing timeout on.- Returns:
falseifkeydoes not exist or does not have an associated timeout,trueif the timeout has been removed.- See Also:
- valkey.io for details.
- Example:
Boolean timeoutRemoved = client.persist(gs("my_key")).get(); assert timeoutRemoved; // Indicates that the timeout associated with the key "my_key" was successfully removed.
-
type
java.util.concurrent.CompletableFuture<java.lang.String> type(java.lang.String key)
Returns the string representation of the type of the value stored atkey.- Parameters:
key- Thekeyto check its data type.- Returns:
- If the
keyexists, the type of the stored value is returned. Otherwise, a "none" string is returned. - See Also:
- valkey.io for details.
- Example:
String type = client.type("StringKey").get(); assert type.equals("string"); type = client.type("ListKey").get(); assert type.equals("list");
-
type
java.util.concurrent.CompletableFuture<java.lang.String> type(GlideString key)
Returns the string representation of the type of the value stored atkey.- Parameters:
key- Thekeyto check its data type.- Returns:
- If the
keyexists, the type of the stored value is returned. Otherwise, a "none" string is returned. - See Also:
- valkey.io for details.
- Example:
String type = client.type(gs("StringKey")).get(); assert type.equals("string"); type = client.type(gs("ListKey")).get(); assert type.equals("list");
-
objectEncoding
java.util.concurrent.CompletableFuture<java.lang.String> objectEncoding(java.lang.String key)
Returns the internal encoding for the Valkey object stored atkey.- Parameters:
key- Thekeyof the object to get the internal encoding of.- Returns:
- If
keyexists, returns the internal encoding of the object stored atkeyas aString. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
String encoding = client.objectEncoding("my_hash").get(); assert encoding.equals("listpack"); encoding = client.objectEncoding("non_existing_key").get(); assert encoding == null;
-
objectEncoding
java.util.concurrent.CompletableFuture<java.lang.String> objectEncoding(GlideString key)
Returns the internal encoding for the Valkey object stored atkey.- Parameters:
key- Thekeyof the object to get the internal encoding of.- Returns:
- If
keyexists, returns the internal encoding of the object stored atkeyas aString. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
String encoding = client.objectEncoding(gs("my_hash")).get(); assert encoding.equals("listpack"); encoding = client.objectEncoding(gs("non_existing_key")).get(); assert encoding == null;
-
objectFreq
java.util.concurrent.CompletableFuture<java.lang.Long> objectFreq(java.lang.String key)
Returns the logarithmic access frequency counter of a Valkey object stored atkey.- Parameters:
key- Thekeyof the object to get the logarithmic access frequency counter of.- Returns:
- If
keyexists, returns the logarithmic access frequency counter of the object stored atkeyas aLong. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long frequency = client.objectFreq("my_hash").get(); assert frequency == 2L; frequency = client.objectFreq("non_existing_key").get(); assert frequency == null;
-
objectFreq
java.util.concurrent.CompletableFuture<java.lang.Long> objectFreq(GlideString key)
Returns the logarithmic access frequency counter of a Valkey object stored atkey.- Parameters:
key- Thekeyof the object to get the logarithmic access frequency counter of.- Returns:
- If
keyexists, returns the logarithmic access frequency counter of the object stored atkeyas aLong. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long frequency = client.objectFreq(gs("my_hash")).get(); assert frequency == 2L; frequency = client.objectFreq(gs("non_existing_key")).get(); assert frequency == null;
-
objectIdletime
java.util.concurrent.CompletableFuture<java.lang.Long> objectIdletime(java.lang.String key)
Returns the time in seconds since the last access to the value stored atkey.- Parameters:
key- Thekeyof the object to get the idle time of.- Returns:
- If
keyexists, returns the idle time in seconds. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long idletime = client.objectIdletime("my_hash").get(); assert idletime == 2L; idletime = client.objectIdletime("non_existing_key").get(); assert idletime == null;
-
objectIdletime
java.util.concurrent.CompletableFuture<java.lang.Long> objectIdletime(GlideString key)
Returns the time in seconds since the last access to the value stored atkey.- Parameters:
key- Thekeyof the object to get the idle time of.- Returns:
- If
keyexists, returns the idle time in seconds. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long idletime = client.objectIdletime(gs("my_hash")).get(); assert idletime == 2L; idletime = client.objectIdletime(gs("non_existing_key")).get(); assert idletime == null;
-
objectRefcount
java.util.concurrent.CompletableFuture<java.lang.Long> objectRefcount(java.lang.String key)
Returns the reference count of the object stored atkey.- Parameters:
key- Thekeyof the object to get the reference count of.- Returns:
- If
keyexists, returns the reference count of the object stored atkeyas aLong. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long refcount = client.objectRefcount("my_hash").get(); assert refcount == 2L; refcount = client.objectRefcount("non_existing_key").get(); assert refcount == null;
-
objectRefcount
java.util.concurrent.CompletableFuture<java.lang.Long> objectRefcount(GlideString key)
Returns the reference count of the object stored atkey.- Parameters:
key- Thekeyof the object to get the reference count of.- Returns:
- If
keyexists, returns the reference count of the object stored atkeyas aLong. Otherwise, returnsnull. - See Also:
- valkey.io for details.
- Example:
Long refcount = client.objectRefcount(gs("my_hash")).get(); assert refcount == 2L; refcount = client.objectRefcount(gs("non_existing_key")).get(); assert refcount == null;
-
rename
java.util.concurrent.CompletableFuture<java.lang.String> rename(java.lang.String key, java.lang.String newKey)RenameskeytonewKey.
IfnewKeyalready exists it is overwritten.- Parameters:
key- The key to rename.newKey- The new name of the key.- Returns:
- If the
keywas successfully renamed, return"OK". Ifkeydoes not exist, an error is thrown. - See Also:
- valkey.io for details.
- Example:
String value = client.set("key", "value").get(); value = client.rename("key", "newKeyName").get(); assert value.equals("OK");
-
rename
java.util.concurrent.CompletableFuture<java.lang.String> rename(GlideString key, GlideString newKey)
RenameskeytonewKey.
IfnewKeyalready exists it is overwritten.- Parameters:
key- The key to rename.newKey- The new name of the key.- Returns:
- If the
keywas successfully renamed, return"OK". Ifkeydoes not exist, an error is thrown. - See Also:
- valkey.io for details.
- Example:
String value = client.set(gs("key"), gs("value")).get(); value = client.rename(gs("key"), gs("newKeyName")).get(); assert value.equals("OK");
-
renamenx
java.util.concurrent.CompletableFuture<java.lang.Boolean> renamenx(java.lang.String key, java.lang.String newKey)RenameskeytonewKeyifnewKeydoes not yet exist.- Parameters:
key- The key to rename.newKey- The new key name.- Returns:
trueifkeywas renamed tonewKey,falseifnewKeyalready exists.- See Also:
- valkey.io for details.
- Example:
Boolean renamed = client.renamenx("old_key", "new_key").get(); assert renamed;
-
renamenx
java.util.concurrent.CompletableFuture<java.lang.Boolean> renamenx(GlideString key, GlideString newKey)
RenameskeytonewKeyifnewKeydoes not yet exist.- Parameters:
key- The key to rename.newKey- The new key name.- Returns:
trueifkeywas renamed tonewKey,falseifnewKeyalready exists.- See Also:
- valkey.io for details.
- Example:
Boolean renamed = client.renamenx(gs("old_key"), gs("new_key")).get(); assert renamed;
-
touch
java.util.concurrent.CompletableFuture<java.lang.Long> touch(java.lang.String[] keys)
Updates the last access time of specifiedkeys.- Parameters:
keys- The keys to update last access time.- Returns:
- The number of keys that were updated.
- See Also:
- valkey.io for details.
- Example:
Long payload = client.touch(new String[] {"myKey1", "myKey2", "nonExistentKey"}).get(); assert payload == 2L; // Last access time of 2 keys has been updated.
-
touch
java.util.concurrent.CompletableFuture<java.lang.Long> touch(GlideString[] keys)
Updates the last access time of specifiedkeys.- Parameters:
keys- The keys to update last access time.- Returns:
- The number of keys that were updated.
- See Also:
- valkey.io for details.
- Example:
Long payload = client.touch(new GlideString[] {gs("myKey1"), gs("myKey2"), gs("nonExistentKey")}).get(); assert payload == 2L; // Last access time of 2 keys has been updated.
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(java.lang.String source, java.lang.String destination)Copies the value stored at thesourceto thedestinationkey if thedestinationkey does not yet exist.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.set("test1", "one").get(); client.set("test2", "two").get(); assert !client.copy("test1", "test2").get(); assert client.copy("test1", "test2").get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(GlideString source, GlideString destination)
Copies the value stored at thesourceto thedestinationkey if thedestinationkey does not yet exist.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.set(gs("test1"), gs("one")).get(); client.set(gs("test2"), gs("two")).get(); assert !client.copy(gs("test1", gs("test2")).get(); assert client.copy(gs("test1"), gs("test2")).get();
-
move
java.util.concurrent.CompletableFuture<java.lang.Boolean> move(java.lang.String key, long dbIndex)Movekeyfrom the currently selected database to the database specified bydbIndex.- Parameters:
key- The key to move.dbIndex- The index of the database to movekeyto.- Returns:
trueifkeywas moved, orfalseif thekeyalready exists in the destination database or does not exist in the source database.- See Also:
- valkey.io for more details.
- Example:
Boolean moved = client.move("some_key", 1L).get(); assert moved;
-
move
java.util.concurrent.CompletableFuture<java.lang.Boolean> move(GlideString key, long dbIndex)
Movekeyfrom the currently selected database to the database specified bydbIndex.- Parameters:
key- The key to move.dbIndex- The index of the database to movekeyto.- Returns:
trueifkeywas moved, orfalseif thekeyalready exists in the destination database or does not exist in the source database.- See Also:
- valkey.io for more details.
- Example:
Boolean moved = client.move(gs("some_key"), 1L).get(); assert moved;
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(java.lang.String source, java.lang.String destination, boolean replace)Copies the value stored at thesourceto thedestinationkey. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.replace- If the destination key should be removed before copying the value to it.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.set("test1", "one").get(); client.set("test2", "two").get(); assert !client.copy("test1", "test2", false).get(); assert client.copy("test1", "test2", true).get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(GlideString source, GlideString destination, boolean replace)
Copies the value stored at thesourceto thedestinationkey. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.replace- If the destination key should be removed before copying the value to it.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.set(gs("test1"), gs("one")).get(); client.set(gs("test2"), gs("two")).get(); assert !client.copy(gs("test1", gs("test2"), false).get(); assert client.copy(gs("test1", gs("test2"), true).get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(java.lang.String source, java.lang.String destination, long destinationDB, boolean replace)Copies the value stored at thesourceto thedestinationkey ondestinationDB. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.destinationDB- The alternative logical database index for the destination key.replace- If the destination key should be removed before copying the value to it.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above for standalone Client.
- See Also:
- valkey.io for details.
- Example:
client.set("test1", "one").get(); assert client.copy("test1", "test2", 1, false).get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(GlideString source, GlideString destination, long destinationDB, boolean replace)
Copies the value stored at thesourceto thedestinationkey ondestinationDB. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.destinationDB- The alternative logical database index for the destination key.replace- If the destination key should be removed before copying the value to it.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above for standalone Client.
- See Also:
- valkey.io for details.
- Example:
client.set(gs("test1"), gs("one")).get(); assert client.copy(gs("test1"), gs("test2"), 1, false).get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(java.lang.String source, java.lang.String destination, long destinationDB)Copies the value stored at thesourceto thedestinationkey ondestinationDB. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.destinationDB- The alternative logical database index for the destination key.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above for standalone Client.
- See Also:
- valkey.io for details.
- Example:
client.set("test1", "one").get(); assert client.copy("test1", "test2", 1).get();
-
copy
java.util.concurrent.CompletableFuture<java.lang.Boolean> copy(GlideString source, GlideString destination, long destinationDB)
Copies the value stored at thesourceto thedestinationkey ondestinationDB. Whenreplaceis true, removes thedestinationkey first if it already exists, otherwise performs no action.- Parameters:
source- The key to the source value.destination- The key where the value should be copied to.destinationDB- The alternative logical database index for the destination key.- Returns:
trueifsourcewas copied,falseifsourcewas not copied.- Since:
- Valkey 6.2.0 and above for standalone Client.
- See Also:
- valkey.io for details.
- Example:
client.set(gs("test1"), gs("one")).get(); assert client.copy(gs("test1"), gs("test2"), 1).get();
-
dump
java.util.concurrent.CompletableFuture<byte[]> dump(GlideString key)
Serialize the value stored atkeyin a Valkey-specific format and return it to the user.- Parameters:
key- Thekeyto serialize.- Returns:
- The serialized value of the data stored at
key.
Ifkeydoes not exist,nullwill be returned. - See Also:
- valkey.io for details.
- Example:
byte[] result = client.dump("myKey").get(); byte[] response = client.dump("nonExistingKey").get(); assert response.equals(null);
-
restore
java.util.concurrent.CompletableFuture<java.lang.String> restore(GlideString key, long ttl, byte[] value)
Create akeyassociated with avaluethat is obtained by deserializing the provided serializedvalue(obtained viadump(glide.api.models.GlideString)).- Parameters:
key- Thekeyto create.ttl- The expiry time (in milliseconds). If0, thekeywill persist.value- The serialized value to deserialize and assign tokey.- Returns:
- Return
OKif successfully create akeywith avalue. - See Also:
- valkey.io for details.
- Example:
String result = client.restore(gs("newKey"), 0, value).get(); assert result.equals("OK");
-
restore
java.util.concurrent.CompletableFuture<java.lang.String> restore(GlideString key, long ttl, byte[] value, RestoreOptions restoreOptions)
Create akeyassociated with avaluethat is obtained by deserializing the provided serializedvalue(obtained viadump(glide.api.models.GlideString)).- Parameters:
key- Thekeyto create.ttl- The expiry time (in milliseconds). If0, thekeywill persist.value- The serialized value to deserialize and assign tokey.restoreOptions- The restore options. SeeRestoreOptions.- Returns:
- Return
OKif successfully create akeywith avalue. - See Also:
- valkey.io for details.
- Example:
RestoreOptions options = RestoreOptions.builder().replace().absttl().idletime(10).frequency(10).build()).get(); // Set restore options with replace and absolute TTL modifiers, object idletime and frequency to 10. String result = client.restore(gs("newKey"), 0, value, options).get(); assert result.equals("OK");
-
sort
java.util.concurrent.CompletableFuture<java.lang.String[]> sort(java.lang.String key)
Sorts the elements in the list, set, or sorted set atkeyand returns the result.
Thesortcommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
To store the result into a new key, seesortStore(String, String).- Parameters:
key- The key of the list, set, or sorted set to be sorted.- Returns:
- An
Arrayof sorted elements. - See Also:
- valkey.io for details.
- Example:
client.lpush("mylist", new String[] {"3", "1", "2"}).get(); assertArrayEquals(new String[] {"1", "2", "3"}, client.sort("mylist").get()); // List is sorted in ascending order
-
sort
java.util.concurrent.CompletableFuture<GlideString[]> sort(GlideString key)
Sorts the elements in the list, set, or sorted set atkeyand returns the result.
Thesortcommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
To store the result into a new key, seesortStore(String, String).- Parameters:
key- The key of the list, set, or sorted set to be sorted.- Returns:
- An
Arrayof sorted elements. - See Also:
- valkey.io for details.
- Example:
client.lpush(gs("mylist"), new GlideString[] {gs("3"), gs("1"), gs("2")}).get(); assertArrayEquals(new GlideString[] {gs("1"), gs("2"), gs("3")}, client.sort(gs("mylist")).get()); // List is sorted in ascending order
-
sort
java.util.concurrent.CompletableFuture<java.lang.String[]> sort(java.lang.String key, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result. Thesortcommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
To store the result into a new key, seesortStore(String, String, SortOptions).- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptions.- Returns:
- An
Arrayof sorted elements. - See Also:
- valkey.io for details.
- Example:
client.hset("user:1", Map.of("name", "Alice", "age", "30")).get(); client.hset("user:2", Map.of("name", "Bob", "age", "25")).get(); client.lpush("user_ids", new String[] {"2", "1"}).get(); String [] payload = client.sort("user_ids", SortOptions.builder().byPattern("user:*->age") .getPattern("user:*->name").build()).get(); assertArrayEquals(new String[] {"Bob", "Alice"}, payload); // Returns a list of the names sorted by age
-
sort
java.util.concurrent.CompletableFuture<GlideString[]> sort(GlideString key, SortOptionsBinary sortOptions)
Sorts the elements in the list, set, or sorted set atkeyand returns the result. Thesortcommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
To store the result into a new key, see#sortStore(GlideString, GlideString, SortOptions).- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptionsBinary.- Returns:
- An
Arrayof sorted elements. - See Also:
- valkey.io for details.
- Example:
client.hset(gs("user:1"), Map.of(gs("name"), gs("Alice"), gs("age"), gs("30"))).get(); client.hset(gs("user:2"), Map.of(gs("name"), gs("Bob"), gs("age"), gs("25"))).get(); client.lpush(gs("user_ids"), new GlideString[] {gs("2"), gs("1")}).get(); GlideString [] payload = client.sort(gs("user_ids"), SortOptionsBinary.builder().byPattern(gs("user:*->age")) .getPattern(gs("user:*->name")).build()).get(); assertArrayEquals(new GlideString[] {gs("Bob"), gs("Alice")}, payload); // Returns a list of the names sorted by age
-
sortReadOnly
java.util.concurrent.CompletableFuture<java.lang.String[]> sortReadOnly(java.lang.String key)
Sorts the elements in the list, set, or sorted set atkeyand returns the result.
ThesortReadOnlycommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
This command is routed depending on the client'sReadFromstrategy.- Parameters:
key- The key of the list, set, or sorted set to be sorted.- Returns:
- An
Arrayof sorted elements. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.lpush("mylist", new String[] {"3", "1", "2"}).get(); assertArrayEquals(new String[] {"1", "2", "3"}, client.sortReadOnly("mylist").get()); // List is sorted in ascending order
-
sortReadOnly
java.util.concurrent.CompletableFuture<GlideString[]> sortReadOnly(GlideString key)
Sorts the elements in the list, set, or sorted set atkeyand returns the result.
ThesortReadOnlycommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
This command is routed depending on the client'sReadFromstrategy.- Parameters:
key- The key of the list, set, or sorted set to be sorted.- Returns:
- An
Arrayof sorted elements. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.lpush(gs("mylist", new GlideString[] {gs("3"), gs("1"), gs("2")}).get(); assertArrayEquals(new GlideString[] {gs("1"), gs("2"), gs("3")}, client.sortReadOnly(gs("mylist")).get()); // List is sorted in ascending order
-
sortReadOnly
java.util.concurrent.CompletableFuture<java.lang.String[]> sortReadOnly(java.lang.String key, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand returns the result. ThesortReadOnlycommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
This command is routed depending on the client'sReadFromstrategy.- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptions.- Returns:
- An
Arrayof sorted elements. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.hset("user:1", Map.of("name", "Alice", "age", "30")).get(); client.hset("user:2", Map.of("name", "Bob", "age", "25")).get(); client.lpush("user_ids", new String[] {"2", "1"}).get(); String [] payload = client.sortReadOnly("user_ids", SortOptions.builder().byPattern("user:*->age") .getPattern("user:*->name").build()).get(); assertArrayEquals(new String[] {"Bob", "Alice"}, payload); // Returns a list of the names sorted by age
-
sortReadOnly
java.util.concurrent.CompletableFuture<GlideString[]> sortReadOnly(GlideString key, SortOptionsBinary sortOptions)
Sorts the elements in the list, set, or sorted set atkeyand returns the result. ThesortReadOnlycommand can be used to sort elements based on different criteria and apply transformations on sorted elements.
This command is routed depending on the client'sReadFromstrategy.- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptions.- Returns:
- An
Arrayof sorted elements. - Since:
- Valkey 7.0 and above.
- See Also:
- valkey.io for details.
- Example:
client.hset(gs("user:1"), Map.of(gs("name"), gs("Alice"), gs("age"), gs("30"))).get(); client.hset(gs("user:2"), Map.of(gs("name"), gs("Bob"), gs("age"), gs("25"))).get(); client.lpush("user_ids", new GlideString[] {gs("2"), gs("1")}).get(); GlideString [] payload = client.sortReadOnly(gs("user_ids"), SortOptionsBinary.builder().byPattern(gs("user:*->age")) .getPattern(gs("user:*->name")).build()).get(); assertArrayEquals(new GlideString[] {gs("Bob"), gs("Alice")}, payload); // Returns a list of the names sorted by age
-
sortStore
java.util.concurrent.CompletableFuture<java.lang.Long> sortStore(java.lang.String key, java.lang.String destination)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination. Thesortcommand can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key.
To get the sort result without storing it into a key, seesort(String)orsortReadOnly(String).- Parameters:
key- The key of the list, set, or sorted set to be sorted.destination- The key where the sorted result will be stored.- Returns:
- The number of elements in the sorted key stored at
destination. - See Also:
- valkey.io for details.
- Example:
client.lpush("mylist", new String[] {"3", "1", "2"}).get(); assert client.sortStore("mylist", "destination").get() == 3; assertArrayEquals( new String[] {"1", "2", "3"}, client.lrange("destination", 0, -1).get()); // Sorted list is stored in `destination`
-
sortStore
java.util.concurrent.CompletableFuture<java.lang.Long> sortStore(GlideString key, GlideString destination)
Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination. Thesortcommand can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key.
To get the sort result without storing it into a key, seesort(GlideString)orsortReadOnly(GlideString).- Parameters:
key- The key of the list, set, or sorted set to be sorted.destination- The key where the sorted result will be stored.- Returns:
- The number of elements in the sorted key stored at
destination. - See Also:
- valkey.io for details.
- Example:
client.lpush(gs("mylist"), new GlideString[] {gs("3"), gs("1"), gs("2")}).get(); assert client.sortStore(gs("mylist"), gs("destination")).get() == 3; assertArrayEquals( new GlideString[] {gs("1"), gs("2"), gs("3")}, client.lrange(gs("destination"), 0, -1).get()); // Sorted list is stored in `destination`
-
sortStore
java.util.concurrent.CompletableFuture<java.lang.Long> sortStore(java.lang.String key, java.lang.String destination, SortOptions sortOptions)Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination. Thesortcommand can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key.
To get the sort result without storing it into a key, seesort(String, SortOptions).- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptions.destination- The key where the sorted result will be stored.- Returns:
- The number of elements in the sorted key stored at
destination. - See Also:
- valkey.io for details.
- Example:
client.hset("user:1", Map.of("name", "Alice", "age", "30")).get(); client.hset("user:2", Map.of("name", "Bob", "age", "25")).get(); client.lpush("user_ids", new String[] {"2", "1"}).get(); Long payload = client.sortStore("user_ids", "destination", SortOptions.builder().byPattern("user:*->age").getPattern("user:*->name").build()) .get(); assertEquals(2, payload); assertArrayEquals( new String[] {"Bob", "Alice"}, client.lrange("destination", 0, -1).get()); // The list of the names sorted by age is stored in `destination`
-
sortStore
java.util.concurrent.CompletableFuture<java.lang.Long> sortStore(GlideString key, GlideString destination, SortOptionsBinary sortOptions)
Sorts the elements in the list, set, or sorted set atkeyand stores the result indestination. Thesortcommand can be used to sort elements based on different criteria, apply transformations on sorted elements, and store the result in a new key.
To get the sort result without storing it into a key, see#sort(GlideString, SortOptions).- Parameters:
key- The key of the list, set, or sorted set to be sorted.sortOptions- TheSortOptionsBinary.destination- The key where the sorted result will be stored.- Returns:
- The number of elements in the sorted key stored at
destination. - See Also:
- valkey.io for details.
- Example:
client.hset(gs("user:1"), Map.of(gs("name"), gs("Alice"), gs("age"), gs("30"))).get(); client.hset(gs("user:2"), Map.of(gs("name"), gs("Bob"), gs("age"), gs("25"))).get(); client.lpush(gs("user_ids"), new GlideString[] {gs("2"), gs("1")}).get(); Long payload = client.sortStore(gs("user_ids"), gs("destination"), SortOptionsBinary.builder().byPattern(gs("user:*->age")).getPattern(gs("user:*->name")).build()) .get(); assertEquals(2, payload); assertArrayEquals( new GlideString[] {gs("Bob"), gs("Alice")}, client.lrange(gs("destination"), 0, -1).get()); // The list of the names sorted by age is stored in `destination`
-
wait
java.util.concurrent.CompletableFuture<java.lang.Long> wait(long numreplicas, long timeout)Blocks the current client until all the previous write commands are successfully transferred and acknowledged by at leastnumreplicasof replicas. Iftimeoutis reached, the command returns even if the specified number of replicas were not yet reached.- Parameters:
numreplicas- The number of replicas to reach.timeout- The timeout value specified in milliseconds. A value of0will block indefinitely.- Returns:
- The number of replicas reached by all the writes performed in the context of the current connection.
- Example:
client.set("key", "value).get(); assert client.wait(1L, 1000L).get() == 1L;
-
waitaof
java.util.concurrent.CompletableFuture<java.lang.Long[]> waitaof(long numlocal, long numreplicas, long timeout)Blocks the current client until all previous write commands are successfully transferred and acknowledged by at leastnumlocalandnumreplicasof replicas. Iftimeoutis reached, the command returns even if the specified number of replicas were not yet reached.- Parameters:
numlocal- The number of local replicas to reach.numreplicas- The number of replicas to reach.timeout- The timeout value specified in milliseconds. A value of0will block indefinitely.- Returns:
- An
arrayof twoLongvalues: the number of local replicas reached and the number of replicas reached. - Since:
- Valkey 7.2 and above.
- See Also:
- valkey.io for details.
- Example:
client.set("key", "value").get(); Long[] result = client.waitaof(1L, 1L, 1000L).get(); assert result[0] >= 1L; // At least 1 local replica reached assert result[1] >= 1L; // At least 1 replica reached
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, java.lang.String key, long destinationDB, long timeout)Atomically transfers a key from a source Valkey instance to a destination Valkey instance. Once the key is successfully transferred, it is deleted from the source instance and is guaranteed to exist in the destination instance.- Parameters:
destinationHost- The destination host.destinationPort- The destination port.key- The key to migrate.destinationDB- The destination database index.timeout- The timeout in milliseconds.- Returns:
"OK"on success, or"NOKEY"if no keys were found in the source instance.- See Also:
- valkey.io for details.
- Example:
client.set("key", "value").get(); String result = client.migrate("destination.example.com", 6379, "key", 0, 5000).get(); assert result.equals("OK");
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, GlideString key, long destinationDB, long timeout)Atomically transfers a key from a source Valkey instance to a destination Valkey instance. Once the key is successfully transferred, it is deleted from the source instance and is guaranteed to exist in the destination instance.Note: The host and port are String/long types because they represent network addresses, while the key can be GlideString to support binary-safe key names.
- Parameters:
destinationHost- The destination host.destinationPort- The destination port.key- The key to migrate (binary-safe).destinationDB- The destination database index.timeout- The timeout in milliseconds.- Returns:
"OK"on success, or"NOKEY"if no keys were found in the source instance.- See Also:
- valkey.io for details.
- Example:
client.set(gs("key"), gs("value")).get(); String result = client.migrate("destination.example.com", 6379, gs("key"), 0, 5000).get(); assert result.equals("OK");
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, java.lang.String key, long destinationDB, long timeout, MigrateOptions migrateOptions)Atomically transfers a key from a source Valkey instance to a destination Valkey instance. Once the key is successfully transferred, it is deleted from the source instance (unless COPY is specified) and is guaranteed to exist in the destination instance.- Parameters:
destinationHost- The destination host.destinationPort- The destination port.key- The key to migrate.destinationDB- The destination database index.timeout- The timeout in milliseconds.migrateOptions- Additional options for the MIGRATE command.- Returns:
"OK"on success, or"NOKEY"if no keys were found in the source instance.- See Also:
- valkey.io for details.
- Example:
client.set("key", "value").get(); MigrateOptions options = MigrateOptions.builder().copy(true).replace(true).build(); String result = client.migrate("destination.example.com", 6379, "key", 0, 5000, options).get(); assert result.equals("OK");
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, GlideString key, long destinationDB, long timeout, MigrateOptions migrateOptions)Atomically transfers a key from a source Valkey instance to a destination Valkey instance. Once the key is successfully transferred, it is deleted from the source instance (unless COPY is specified) and is guaranteed to exist in the destination instance.Note: The host and port are String/long types because they represent network addresses, while the key can be GlideString to support binary-safe key names.
- Parameters:
destinationHost- The destination host.destinationPort- The destination port.key- The key to migrate (binary-safe).destinationDB- The destination database index.timeout- The timeout in milliseconds.migrateOptions- Additional options for the MIGRATE command.- Returns:
"OK"on success, or"NOKEY"if no keys were found in the source instance.- See Also:
- valkey.io for details.
- Example:
client.set(gs("key"), gs("value")).get(); MigrateOptions options = MigrateOptions.builder().copy(true).replace(true).build(); String result = client.migrate("destination.example.com", 6379, gs("key"), 0, 5000, options).get(); assert result.equals("OK");
-
-