Reputation: 97
I need to make native queries to Redis in the Java code. Is there a Java library or another way to do this?
I need something like this:
someRedisClient.execute("FT.SEARCH SOME_INDEX (@foo:bar*)")
I didn't find such feature in lettuce, lettusearch, redisson.
Upvotes: 0
Views: 1529
Reputation: 6267
Jedis has sendCommand
methods which supports what you want but with a caveat. The method signatures are as follows:
Object sendCommand(ProtocolCommand cmd, byte[]... args)
Object sendCommand(ProtocolCommand cmd, String... args)
As you can see, you must have an implementation of ProtocolCommand representing the actual command. It is commonly done by enum
.
public enum Command implements ProtocolCommand {
FT_SEARCH("FT.SEARCH");
private final byte[] raw;
private Command(String str) {
raw = str.getBytes();
}
@Override
public byte[] getRaw() {
return raw;
}
}
After that,
jedis.sendCommand(Command.FT_SEARCH, "SOME_INDEX", "(@foo:bar*)");
Yes, the command arguments are separate strings, instead of concatenated by space.
Upvotes: 3