Package glide.api.commands
Interface GenericCommands
-
- All Known Implementing Classes:
GlideClient
public interface GenericCommandsSupports commands for the "Generic Commands" group for a standalone client.- See Also:
- Generic Commands
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<java.lang.Object>customCommand(GlideString[] args)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<java.lang.Object>customCommand(java.lang.String[] args)Executes a single command, without checking inputs.java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, GlideString[] keys, long destinationDB, long timeout)Binary variant ofmigrate(String, long, String[], long, long).java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, GlideString[] keys, long destinationDB, long timeout, MigrateOptions migrateOptions)Binary variant ofmigrate(String, long, String[], long, long, MigrateOptions).java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, java.lang.String[] keys, long destinationDB, long timeout)Migrate multiple keys from the current server to a destination server.java.util.concurrent.CompletableFuture<java.lang.String>migrate(java.lang.String destinationHost, long destinationPort, java.lang.String[] keys, long destinationDB, long timeout, MigrateOptions migrateOptions)Migrate multiple keys from the current server to a destination server with options.java.util.concurrent.CompletableFuture<java.lang.String>randomKey()Returns a random key from currently selected database.java.util.concurrent.CompletableFuture<GlideString>randomKeyBinary()Returns a random key from currently selected database.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(GlideString cursor)Iterates incrementally over a database for matching keys.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(GlideString cursor, ScanOptions options)Iterates incrementally over a database for matching keys.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(java.lang.String cursor)Iterates incrementally over a database for matching keys.java.util.concurrent.CompletableFuture<java.lang.Object[]>scan(java.lang.String cursor, ScanOptions options)Iterates incrementally over a database for matching keys.
-
-
-
Method Detail
-
customCommand
java.util.concurrent.CompletableFuture<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.- Parameters:
args- Arguments for the custom command.- 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:
Object response = client.customCommand(new String[] {"ping", "GLIDE"}).get(); assert response.equals("GLIDE"); // Get a list of all pub/sub clients: Object result = client.customCommand(new String[]{ "CLIENT", "LIST", "TYPE", "PUBSUB" }).get();
-
customCommand
java.util.concurrent.CompletableFuture<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.- Parameters:
args- Arguments for the custom command.- 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:
Object response = client.customCommand(new GlideString[] {gs("ping"), gs("GLIDE")}).get(); assert response.equals(gs("GLIDE")); // Get a list of all pub/sub clients: Object result = client.customCommand(new GlideString[] { gs("CLIENT"), gs("LIST"), gs("TYPE"), gs("PUBSUB") }).get();
-
randomKey
java.util.concurrent.CompletableFuture<java.lang.String> randomKey()
Returns a random key from currently selected database.- 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 from currently selected database.- 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(); String 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(java.lang.String cursor)
Iterates incrementally over a database for matching keys.- Parameters:
cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the scan.
The second element is always anArrayof matched keys from the database. - See Also:
- valkey.io for details.
- Example:
// Assume database contains a set with 200 keys String cursor = "0"; Object[] result; do { result = client.scan(cursor).get(); cursor = result[0].toString(); Object[] stringResults = (Object[]) result[1]; String keyList = Arrays.stream(stringResults) .map(obj -> (String)obj) .collect(Collectors.joining(", ")); System.out.println("\nSCAN iteration: " + keyList); } while (!cursor.equals("0"));
-
scan
java.util.concurrent.CompletableFuture<java.lang.Object[]> scan(GlideString cursor)
Iterates incrementally over a database for matching keys.- Parameters:
cursor- The cursor that points to the next iteration of results. A value ofgs("0")indicates the start of the search.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results.gs("0")will be thecursorreturned on the last iteration of the scan.
The second element is always anArrayof matched keys from the database. - See Also:
- valkey.io for details.
- Example:
// Assume database contains a set with 200 keys GlideString cursor = gs("0"); Object[] result; do { result = client.scan(cursor).get(); cursor = gs(result[0].toString()); Object[] stringResults = (Object[]) result[1]; String keyList = Arrays.stream(stringResults) .map(obj -> obj.toString()) .collect(Collectors.joining(", ")); System.out.println("\nSCAN iteration: " + keyList); } while (!cursor.equals(gs("0")));
-
scan
java.util.concurrent.CompletableFuture<java.lang.Object[]> scan(java.lang.String cursor, ScanOptions options)Iterates incrementally over a database for matching keys.- Parameters:
cursor- The cursor that points to the next iteration of results. A value of"0"indicates the start of the search.options- TheScanOptions.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results."0"will be thecursorreturned on the last iteration of the scan.
The second element is always anArrayof matched keys from the database. - See Also:
- valkey.io for details.
- Example:
// Assume database contains a set with 200 keys String cursor = "0"; Object[] result; // match keys on pattern *11* ScanOptions options = ScanOptions.builder().matchPattern("*11*").build(); do { result = client.scan(cursor, options).get(); cursor = result[0].toString(); Object[] stringResults = (Object[]) result[1]; String keyList = Arrays.stream(stringResults) .map(obj -> (String)obj) .collect(Collectors.joining(", ")); System.out.println("\nSCAN iteration: " + keyList); } while (!cursor.equals("0"));
-
scan
java.util.concurrent.CompletableFuture<java.lang.Object[]> scan(GlideString cursor, ScanOptions options)
Iterates incrementally over a database for matching keys.- Parameters:
cursor- The cursor that points to the next iteration of results. A value ofgs("0")indicates the start of the search.options- TheScanOptions.- Returns:
- An
ArrayofObjects. The first element is always thecursorfor the next iteration of results.gs("0")will be thecursorreturned on the last iteration of the scan.
The second element is always anArrayof matched keys from the database. - See Also:
- valkey.io for details.
- Example:
// Assume database contains a set with 200 keys GlideString cursor = gs("0"); Object[] result; // match keys on pattern *11* ScanOptions options = ScanOptions.builder().matchPattern("*11*").build(); do { result = client.scan(cursor, options).get(); cursor = gs(result[0].toString()); Object[] stringResults = (Object[]) result[1]; String keyList = Arrays.stream(stringResults) .map(obj -> obj.toString()) .collect(Collectors.joining(", ")); System.out.println("\nSCAN iteration: " + keyList); } while (!cursor.equals(gs("0")));
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, java.lang.String[] keys, long destinationDB, long timeout)Migrate multiple keys from the current server to a destination server. This command is for standalone clients only (not cluster mode).- Parameters:
destinationHost- Hostname or IP address of the destination server.destinationPort- Port of the destination server.keys- The keys to migrate. Must not be null or empty.destinationDB- The database index on the destination server.timeout- Maximum idle time in milliseconds for the bulk-transfer.- Returns:
"OK"on success.- Throws:
java.lang.IllegalArgumentException- if keys is null or empty.- See Also:
- valkey.io for details.
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, GlideString[] keys, long destinationDB, long timeout)Binary variant ofmigrate(String, long, String[], long, long).
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, java.lang.String[] keys, long destinationDB, long timeout, MigrateOptions migrateOptions)Migrate multiple keys from the current server to a destination server with options.- Parameters:
destinationHost- Hostname or IP address of the destination server.destinationPort- Port of the destination server.keys- The keys to migrate. Must not be null or empty.destinationDB- The database index on the destination server.timeout- Maximum idle time in milliseconds for the bulk-transfer.migrateOptions- Additional options.- Returns:
"OK"on success.- Throws:
java.lang.IllegalArgumentException- if keys is null or empty.- See Also:
- valkey.io for details.
-
migrate
java.util.concurrent.CompletableFuture<java.lang.String> migrate(java.lang.String destinationHost, long destinationPort, GlideString[] keys, long destinationDB, long timeout, MigrateOptions migrateOptions)Binary variant ofmigrate(String, long, String[], long, long, MigrateOptions).
-
-