Skip to content

Commit

Permalink
Update examples with more examples
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Jan 8, 2024
1 parent ac74620 commit 6ae5e39
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 10 deletions.
4 changes: 2 additions & 2 deletions java/client/src/main/java/glide/api/RedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import static glide.ffi.resolvers.SocketListenerResolver.getSocket;

import glide.api.commands.BaseCommands;
import glide.api.commands.Command;
import glide.api.models.Command;
import glide.api.commands.RedisExceptionCheckedFunction;
import glide.api.commands.StringCommands;
import glide.api.commands.Transaction;
import glide.api.models.Transaction;
import glide.api.commands.VoidCommands;
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SetOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package glide.api.commands;

import glide.api.models.Transaction;
import glide.ffi.resolvers.RedisValueResolver;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down
11 changes: 8 additions & 3 deletions java/client/src/main/java/glide/api/commands/VoidCommands.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package glide.api.commands;

import glide.api.models.Ok;
import glide.api.models.exceptions.RedisException;
import java.util.concurrent.CompletableFuture;
import response.ResponseOuterClass.Response;

/** Void Commands interface to handle commands that have no payload. */
public interface VoidCommands {

public static Ok OK = new Ok();

/**
* Check for errors in the Response and return null Throws an error if an unexpected value is
* returned
*
* @return null if the response is empty
* TODO: confirm that we want to return Ok - instead of null
* @return Ok if the response is empty
*/
static Void handleVoidResponse(Response response) {
static Ok handleVoidResponse(Response response) {
// return function to convert protobuf.Response into the response object by
// calling valueFromPointer
Object value = BaseCommands.applyBaseCommandResponseResolver().apply(response);
if (value == null) {
return null;
// TODO: confirm that we want to return Ok - instead of null
return OK;
}
throw new RedisException(
"Unexpected return type from Redis: got " + value.getClass() + " expected null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package glide.api.commands;
package glide.api.models;

import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down
15 changes: 15 additions & 0 deletions java/client/src/main/java/glide/api/models/Ok.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package glide.api.models;

public class Ok {

public static final String OK = "OK";

public boolean isEqual(Object object) {
return object instanceof Ok;
}

public String toString() {
return OK;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package glide.api.commands;
package glide.api.models;

/** Class for encapsulating multi-request Transactions to Redis. */
public class Transaction {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package glide.managers;

import glide.api.commands.Command;
import glide.api.models.Command;
import glide.api.commands.RedisExceptionCheckedFunction;
import glide.connectors.handlers.ChannelHandler;
import java.util.concurrent.CompletableFuture;
Expand Down
2 changes: 1 addition & 1 deletion java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import glide.api.commands.Command;
import glide.api.models.Command;
import glide.api.models.commands.SetOptions;
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.mockito.Mockito.when;

import glide.api.commands.BaseCommandResponseResolver;
import glide.api.commands.Command;
import glide.api.models.Command;
import glide.api.models.exceptions.ClosingException;
import glide.api.models.exceptions.ConnectionException;
import glide.api.models.exceptions.ExecAbortException;
Expand Down
10 changes: 10 additions & 0 deletions java/examples/src/main/java/glide/examples/ExamplesApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,23 @@ private static void runGlideExamples() {
RedisClient client = GlideClient.connectToGlide(settings);

System.out.println("Glide PING: " + client.ping().get());
System.out.println("Glide PING(custom): " + client.ping("found you!").get());

// panic
// System.out.println("Glide INFO(): " + client.info().get());

System.out.println("Glide SET(myKey, myValue): " + client.set("myKey", "myValue").get());
System.out.println("Glide GET(myKey): " + client.get("myKey").get());
System.out.println("Glide SET(myKey, yourValue): " + client.set("myKey", "yourValue").get());
System.out.println("Glide GET(myKey): " + client.get("myKey").get());
System.out.println("Glide GET(invalid): " + client.get("invalid").get());

Object customGetMyKey = client.customCommand(new String[]{"get", "myKey"}).get();
System.out.println("Glide CUSTOM_COMMAND(get, myKey): " + customGetMyKey);

Object customGetInvalid = client.customCommand(new String[]{"get", "invalid"}).get();
System.out.println("Glide CUSTOM_COMMAND(get, invalid): " + customGetInvalid);

} catch (ExecutionException | InterruptedException e) {
System.out.println("Glide example failed with an exception: ");
e.printStackTrace();
Expand Down

0 comments on commit 6ae5e39

Please sign in to comment.