Command String Arguments
Valkey strings store sequences of bytes, that may include text, serialized objects, or binary arrays. As such, to pass Valkey strings as arguments to commands, or receive Valkey strings in responses, Glide offers two APIs:
String: for common caseUTF-8converted strings keys andStringobjects can be passed and receives as a JavaString.GlideString: to passbyte[]data, aGlideStringcontainer object can be passed as an argument to a command or received as a response from a command.
A rule about the API:
- Command signatures either take and return
String’s orGlideString’s, but not both. String’s are returned if the commands are passed inString’s. e.gCompletableFuture<String[]> mget(String[] keys)GlideStrings’s are returned if the commands are passed inGlideStrings’s. e.gCompletableFuture<GlideString[]> mget(GlideString[] keys)
Arguments for commands that require a String can also be substituted with GlideString in order to pass in or return a binary value.
gs()is a static constructor that can be called with abyte[]orStringargument to convert toGlideString. For example,
byte[] byteKey = Base64.getDecoder().decode("byteKey");client.set(gs(byteKey), gs("GlideString value")).get();- A
GlideString byte[]object can be converted toUTF-8 Stringby calling.getString()on theGlideStringobject. For example,
client.get(gs(byteKey)).get(); // "GlideString value" as a GlideStringclient.get(gs(byteKey)).get().getString(); // "GlideString value" as a String