Interface GenericClusterCommands
-
- All Known Implementing Classes:
GlideClusterClient
public interface GenericClusterCommandsSupports commands for the "Generic Commands" group for a cluster client.- See Also:
- Generic Commands
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>>customCommand(GlideString[] args)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>>customCommand(GlideString[] args, RequestRoutingConfiguration.Route route)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>>customCommand(java.lang.String[] args)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>>customCommand(java.lang.String[] args, RequestRoutingConfiguration.Route route)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<java.lang.String>randomKey()Returns a random key.
The command will be routed to all primary nodes, and will return the first successful result.java.util.concurrent.CompletableFuture<java.lang.String>randomKey(RequestRoutingConfiguration.Route route)Returns a random key.java.util.concurrent.CompletableFuture<GlideString>randomKeyBinary()Returns a random key.
The command will be routed to all primary nodes, and will return the first successful result.java.util.concurrent.CompletableFuture<GlideString>randomKeyBinary(RequestRoutingConfiguration.Route route)Returns a random key.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(ClusterScanCursor cursor)Incrementally iterates over the keys in the Cluster.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(ClusterScanCursor cursor, ScanOptions options)Incrementally iterates over the keys in the Cluster.java.util.concurrent.CompletableFuture<java.lang.Object[]>scanBinary(ClusterScanCursor cursor)Incrementally iterates over the keys in the Cluster.java.util.concurrent.CompletableFuture<java.lang.Object[]>scanBinary(ClusterScanCursor cursor, ScanOptions options)Incrementally iterates over the keys in the Cluster.
-
-
-
Method Detail
-
customCommand
java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand(java.lang.String[] args)
Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value inargs.
The command will be routed automatically based on the passed command's default request policy.- Parameters:
args- Arguments for the custom command including the command name.- Returns:
- The returned value for the custom command.
- See Also:
- Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
- Example:
ClusterValue<Object> data = client.customCommand(new String[] {"ping"}).get(); assert data.getSingleValue().equals("PONG");
-
customCommand
java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand(GlideString[] args)
Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value inargs.
The command will be routed automatically based on the passed command's default request policy.- Parameters:
args- Arguments for the custom command including the command name.- Returns:
- The returned value for the custom command.
- See Also:
- Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
- Example:
ClusterValue<Object> data = client.customCommand(new GlideString[] {gs("ping")}).get(); assert data.getSingleValue().equals(gs("PONG"));
-
customCommand
java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand(java.lang.String[] args, RequestRoutingConfiguration.Route route)
Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value inargs.- Parameters:
args- Arguments for the custom command including the command nameroute- Specifies the routing configuration for the command. The client will route the command to the nodes defined byroute.- Returns:
- The returning value depends on the executed command and route.
- See Also:
- Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
- Example:
ClusterValue<Object> result = clusterClient.customCommand(new String[]{ "CONFIG", "GET", "maxmemory"}, ALL_NODES).get(); Map<String, Object> payload = result.getMultiValue(); assert payload.get("node1").equals("1GB"); assert payload.get("node2").equals("100MB");
-
customCommand
java.util.concurrent.CompletableFuture<ClusterValue<java.lang.Object>> customCommand(GlideString[] args, RequestRoutingConfiguration.Route route)
Executes a single command, without checking inputs. Every part of the command, including subcommands, should be added as a separate value inargs.- Parameters:
args- Arguments for the custom command including the command nameroute- Specifies the routing configuration for the command. The client will route the command to the nodes defined byroute.- Returns:
- The returning value depends on the executed command and route.
- See Also:
- Valkey GLIDE Wiki for details on the restrictions and limitations of the custom command API.
- Example:
ClusterValue<Object> result = clusterClient.customCommand(new GlideString[] { gs("CONFIG"), gs("GET"), gs("maxmemory") }, ALL_NODES).get(); Map<String, Object> payload = result.getMultiValue(); assert payload.get(gs("node1")).equals(gs("1GB")); assert payload.get(gs("node2")).equals(gs("100MB"));
-
randomKey
java.util.concurrent.CompletableFuture<java.lang.String> randomKey(RequestRoutingConfiguration.Route route)
Returns a random key.- Parameters:
route- Specifies the routing configuration for the command. The client will route the command to the nodes defined byroute, and will return the first successful result.- Returns:
- A random
keyfrom the database. - See Also:
- valkey.io for details.
- Example:
String value = client.set("key", "value").get(); String value_1 = client.set("key1", "value_1").get(); String key = client.randomKey(RANDOM).get(); System.out.println("The random key is: " + key); // The value of key is either "key" or "key1"
-
randomKeyBinary
java.util.concurrent.CompletableFuture<GlideString> randomKeyBinary(RequestRoutingConfiguration.Route route)
Returns a random key.- Parameters:
route- Specifies the routing configuration for the command. The client will route the command to the nodes defined byroute, and will return the first successful result.- Returns:
- A random
keyfrom the database. - See Also:
- valkey.io for details.
- Example:
String value = client.set("key", "value").get(); String value_1 = client.set("key1", "value_1").get(); GlideString key = client.randomKeyBinary(RANDOM).get(); System.out.println("The random key is: " + key); // The value of key is either "key" or "key1"
-
randomKey
java.util.concurrent.CompletableFuture<java.lang.String> randomKey()
Returns a random key.
The command will be routed to all primary nodes, and will return the first successful result.- Returns:
- A random
keyfrom the database. - See Also:
- valkey.io for details.
- Example:
String value = client.set("key", "value").get(); String value_1 = client.set("key1", "value_1").get(); String key = client.randomKey().get(); System.out.println("The random key is: " + key); // The value of key is either "key" or "key1"
-
randomKeyBinary
java.util.concurrent.CompletableFuture<GlideString> randomKeyBinary()
Returns a random key.
The command will be routed to all primary nodes, and will return the first successful result.- Returns:
- A random
keyfrom the database. - See Also:
- valkey.io for details.
- Example:
String value = client.set(gs("key"),gs( "value")).get(); String value_1 = client.set(gs("key1"), gs("value_1")).get(); GlideString key = client.randomKeyBinary().get(); System.out.println("The random key is: " + key); // The value of key is either "key" or "key1"
-
scan
java.util.concurrent.CompletableFuture<java.lang.Object[]> scan(ClusterScanCursor cursor)
Incrementally iterates over the keys in the Cluster.This command is similar to the
SCANcommand, but it is designed to work in a Cluster environment. The main difference is that this command uses aClusterScanCursorobject to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.As with the
SCANcommand, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as thecursorargument in the next call. The iteration terminates when the returned cursorClusterScanCursor.isFinished()returnstrue.This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.
Note that the same key may be returned in multiple scan iterations.
How to use the
ClusterScanCursor:
For each iteration, the previous scanClusterScanCursorobject should be used to continue theSCANby passing it in thecursorargument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.When the cursor is no longer needed, call
ClusterScanCursor.releaseCursorHandle()to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls toSCAN.- Parameters:
cursor- TheClusterScanCursorobject that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor usingClusterScanCursor.initialCursor().- Returns:
- An
Arraywith two elements. The first element is always theClusterScanCursorfor the next iteration of results. To see if there is more data on the given cursor, callClusterScanCursor.isFinished(). To release resources for the current cursor immediately, callClusterScanCursor.releaseCursorHandle()after using the cursor in a call to this method. The cursor cannot be used in a scan again afterClusterScanCursor.releaseCursorHandle()has been called. The second element is anArrayofStringelements each representing a key. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 keys ClusterScanCursor cursor = ClusterScanCursor.initialCursor(); Object[] result; while (!cursor.isFinished()) { result = client.scan(cursor).get(); cursor.releaseCursorHandle(); cursor = (ClusterScanCursor) result[0]; Object[] stringResults = (Object[]) result[1]; System.out.println("\nSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); }
-
scanBinary
java.util.concurrent.CompletableFuture<java.lang.Object[]> scanBinary(ClusterScanCursor cursor)
Incrementally iterates over the keys in the Cluster.This command is similar to the
SCANcommand, but it is designed to work in a Cluster environment. The main difference is that this command uses aClusterScanCursorobject to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.As with the
SCANcommand, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as thecursorargument in the next call. The iteration terminates when the returned cursorClusterScanCursor.isFinished()returnstrue.This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.
Note that the same key may be returned in multiple scan iterations.
How to use the
ClusterScanCursor:
For each iteration, the previous scanClusterScanCursorobject should be used to continue theSCANby passing it in thecursorargument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.When the cursor is no longer needed, call
ClusterScanCursor.releaseCursorHandle()to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls toSCAN.- Parameters:
cursor- TheClusterScanCursorobject that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor usingClusterScanCursor.initialCursor().- Returns:
- An
Arraywith two elements. The first element is always theClusterScanCursorfor the next iteration of results. To see if there is more data on the given cursor, callClusterScanCursor.isFinished(). To release resources for the current cursor immediately, callClusterScanCursor.releaseCursorHandle()after using the cursor in a call to this method. The cursor cannot be used in a scan again afterClusterScanCursor.releaseCursorHandle()has been called. The second element is anArrayofGlideStringelements each representing a key. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 keys ClusterScanCursor cursor = ClusterScanCursor.initialCursor(); Object[] result; while (!cursor.isFinished()) { result = client.scan(cursor).get(); cursor.releaseCursorHandle(); cursor = (ClusterScanCursor) result[0]; Object[] glideStringResults = (Object[]) result[1]; System.out.println("\nSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); }
-
scan
java.util.concurrent.CompletableFuture<java.lang.Object[]> scan(ClusterScanCursor cursor, ScanOptions options)
Incrementally iterates over the keys in the Cluster.This command is similar to the
SCANcommand, but it is designed to work in a Cluster environment. The main difference is that this command uses aClusterScanCursorobject to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.As with the
SCANcommand, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as thecursorargument in the next call. The iteration terminates when the returned cursorClusterScanCursor.isFinished()returnstrue.This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.
Note that the same key may be returned in multiple scan iterations.
How to use the
ClusterScanCursor:
For each iteration, the previous scanClusterScanCursorobject should be used to continue theSCANby passing it in thecursorargument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.When the cursor is no longer needed, call
ClusterScanCursor.releaseCursorHandle()to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls toSCAN.- Parameters:
cursor- TheClusterScanCursorobject that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor usingClusterScanCursor.initialCursor().options- TheScanOptions.- Returns:
- An
Arraywith two elements. The first element is always theClusterScanCursorfor the next iteration of results. To see if there is more data on the given cursor, callClusterScanCursor.isFinished(). To release resources for the current cursor immediately, callClusterScanCursor.releaseCursorHandle()after using the cursor in a call to this method. The cursor cannot be used in a scan again afterClusterScanCursor.releaseCursorHandle()has been called. The second element is anArrayofStringelements each representing a key. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 keys ClusterScanCursor cursor = ClusterScanCursor.initialCursor(); // Scan for keys with archived in the name ScanOptions options = ScanOptions.builder().matchPattern("*archived*").build(); Object[] result; while (!cursor.isFinished()) { result = client.scan(cursor, options).get(); cursor.releaseCursorHandle(); cursor = (ClusterScanCursor) result[0]; Object[] stringResults = (Object[]) result[1]; System.out.println("\nSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); }
-
scanBinary
java.util.concurrent.CompletableFuture<java.lang.Object[]> scanBinary(ClusterScanCursor cursor, ScanOptions options)
Incrementally iterates over the keys in the Cluster.This command is similar to the
SCANcommand, but it is designed to work in a Cluster environment. The main difference is that this command uses aClusterScanCursorobject to manage iterations. For more information about the Cluster Scan implementation, see Cluster Scan.As with the
SCANcommand, this command is a cursor-based iterator. This means that at every call of the command, the server returns an updated cursor (ClusterScanCursor) that the user needs to re-send as thecursorargument in the next call. The iteration terminates when the returned cursorClusterScanCursor.isFinished()returnstrue.This method guarantees that all keyslots available when the first SCAN is called will be scanned before the cursor is finished. Any keys added after the initial scan request is made are not guaranteed to be scanned.
Note that the same key may be returned in multiple scan iterations.
How to use the
ClusterScanCursor:
For each iteration, the previous scanClusterScanCursorobject should be used to continue theSCANby passing it in thecursorargument. Using the same cursor object for multiple iterations may result in the same keys returned or unexpected behavior.When the cursor is no longer needed, call
ClusterScanCursor.releaseCursorHandle()to immediately free resources tied to the cursor. Note that this makes the cursor unusable in subsequent calls toSCAN.- Parameters:
cursor- TheClusterScanCursorobject that wraps the scan state. To start a new scan, create a new empty ClusterScanCursor usingClusterScanCursor.initialCursor().options- TheScanOptions.- Returns:
- An
Arraywith two elements. The first element is always theClusterScanCursorfor the next iteration of results. To see if there is more data on the given cursor, callClusterScanCursor.isFinished(). To release resources for the current cursor immediately, callClusterScanCursor.releaseCursorHandle()after using the cursor in a call to this method. The cursor cannot be used in a scan again afterClusterScanCursor.releaseCursorHandle()has been called. The second element is anArrayofGlideStringelements each representing a key. - See Also:
- valkey.io for details.
- Example:
// Assume key contains a set with 200 keys ClusterScanCursor cursor = ClusterScanCursor.initialCursor(); // Scan for keys with archived in the name ScanOptions options = ScanOptions.builder().matchPattern("*archived*").build(); Object[] result; while (!cursor.isFinished()) { result = client.scan(cursor, options).get(); cursor.releaseCursorHandle(); cursor = (ClusterScanCursor) result[0]; Object[] glideStringResults = (Object[]) result[1]; System.out.println("\nSCAN iteration:"); Arrays.asList(stringResults).stream().forEach(i -> System.out.print(i + ", ")); }
-
-