Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add examples to missing commands and minor fixes for Generic Commands. #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public interface GenericBaseCommands {
* @see <a href="https://redis.io/commands/del/">redis.io</a> for details.
* @param keys The keys we wanted to remove.
* @return The number of keys that were removed.
* @example
* <pre>
* Long num = client.del(new String[] {"key1", "key2"}).get()
* assert num == 2l;
* </pre>
*/
CompletableFuture<Long> del(String[] keys);

Expand All @@ -29,10 +34,10 @@ public interface GenericBaseCommands {
* @return The number of keys that exist. If the same existing key is mentioned in <code>keys
* </code> multiple times, it will be counted multiple times.
* @example
* <p><code>
* long result = client.exists(new String[] {"my_key", "invalid_key"}).get();
* <pre>
* Long result = client.exists(new String[] {"my_key", "invalid_key"}).get();
* assert result == 1L;
* </code>
* </pre>
*/
CompletableFuture<Long> exists(String[] keys);

Expand All @@ -46,9 +51,8 @@ public interface GenericBaseCommands {
* @param keys The list of keys to unlink.
* @return The number of <code>keys</code> that were unlinked.
* @example
* <p>
* <pre>
* long result = client.unlink("my_key").get();
* Long result = client.unlink("my_key").get();
* assert result == 1L;
* </pre>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public interface GenericClusterCommands {
* response (such as <em>XREAD</em>), or that change the client's behavior (such as entering
* <em>pub</em>/<em>sub</em> mode on <em>RESP2</em> connections) shouldn't be called using
* this function.
* @example Returns a list of all <em>pub</em>/<em>sub</em> clients:
* <p><code>
* Object result = client.customCommand(new String[]{ "CLIENT", "LIST", "TYPE", "PUBSUB" }).get();
* </code>
* @param args Arguments for the custom command including the command name.
* @return Response from Redis containing an <code>Object</code>.
* @example
* <pre>
* ClusterValue<Object> data = client.customCommand(new String[] {"ping"}).get();
* assert ((String) data.getSingleValue()).equals("PONG");
* </pre>
*/
CompletableFuture<ClusterValue<Object>> customCommand(String[] args);

Expand All @@ -46,13 +47,16 @@ public interface GenericClusterCommands {
* response (such as <em>XREAD</em>), or that change the client's behavior (such as entering
* <em>pub</em>/<em>sub</em> mode on <em>RESP2</em> connections) shouldn't be called using
* this function.
* @example Returns a list of all <em>pub</em>/<em>sub</em> clients:
* <p><code>
* Object result = client.customCommand(new String[]{ "CLIENT", "LIST", "TYPE", "PUBSUB" }, RANDOM).get();
* </code>
* @param args Arguments for the custom command including the command name
* @param route Routing configuration for the command
* @return Response from Redis containing an <code>Object</code>.
* @example
* <pre>
* ClusterValue&lt;Object&gt; result = clusterClient.customCommand(new String[]{ "CONFIG", "GET", "maxmemory"}, ALL_NODES).get();
* Map&lt;String, Object&gt; payload = result.getMultiValue();
* assert ((String) payload.get("node1")).equals("1GB");
* assert ((String) payload.get("node2")).equals("100MB");
* </pre>
*/
CompletableFuture<ClusterValue<Object>> customCommand(String[] args, Route route);

Expand All @@ -73,6 +77,13 @@ public interface GenericClusterCommands {
* <li>If the transaction failed due to a <code>WATCH</code> command, <code>exec</code> will
* return <code>null</code>.
* </ul>
*
* @example
* <pre>
* ClusterTransaction transaction = new ClusterTransaction().customCommand(new String[] {"info"});
* Object[] result = clusterClient.exec(transaction).get();
* assert ((String) result[0]).contains("# Stats");
* </pre>
*/
CompletableFuture<Object[]> exec(ClusterTransaction transaction);

Expand All @@ -92,6 +103,14 @@ public interface GenericClusterCommands {
* <li>If the transaction failed due to a <code>WATCH</code> command, <code>exec</code> will
* return <code>null</code>.
* </ul>
*
* @example
* <pre>
* ClusterTransaction transaction = new ClusterTransaction().ping().info();
* ClusterValue<Object>[] result = clusterClient.exec(transaction, RANDOM).get();
* assert ((String) result[0].getSingleValue()).equals("PONG");
* assert ((String) result[1].getSingleValue()).contains("# Stats");
* </pre>
*/
CompletableFuture<ClusterValue<Object>[]> exec(ClusterTransaction transaction, Route route);
}
12 changes: 12 additions & 0 deletions java/client/src/main/java/glide/api/commands/GenericCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public interface GenericCommands {
*
* @param args Arguments for the custom command.
* @return Response from Redis containing an <code>Object</code>.
* @example
* <pre>
* Object response = (String) client.customCommand(new String[] {"ping", "GLIDE"}).get()
* assert ((String) response).equals("GLIDE");
* </pre>
*/
CompletableFuture<Object> customCommand(String[] args);

Expand All @@ -45,6 +50,13 @@ public interface GenericCommands {
* <li>If the transaction failed due to a <code>WATCH</code> command, <code>exec</code> will
* return <code>null</code>.
* </ul>
*
* @example
* <pre>
* Transaction transaction = new Transaction().customCommand(new String[] {"info"});
* Object[] result = client.exec(transaction).get();
* assert ((String) result[0]).contains("# Stats");
* </pre>
*/
CompletableFuture<Object[]> exec(Transaction transaction);
}
Loading