Reputation: 2730
I'm using tile38.com with lettuce.io on Java. I'm trying to send a custom NEARBY fleet FENCE POINT 33.462 -112.268 6000
command as per the docs enter link description here, but I don't know how to.
I've been using the CommandType
in Lettuce, but I can't find a way of sending a NEARBY
. Does someone know how I could do it?
Thanks
Upvotes: 5
Views: 2424
Reputation: 18119
You have multiple options to send custom commands:
With custom commands, you basically define a type implementing the ProtocolKeyword
interface which helps you as a single point of reference for all your keywords involved in your commands. You can use synchronous, asynchronous, or reactive APIs to invoke the command:
enum MyKeywords implements ProtocolKeyword {
NEARBY, FENCE, POINT;
private final byte name[];
MyKeywords() {
// cache the bytes for the command name. Reduces memory and cpu pressure when using commands.
name = name().getBytes();
}
@Override
public byte[] getBytes() {
return name;
}
}
CommandArgs<String, String> args = new CommandArgs<>(codec).addKey(key).add(MyKeywords.FENCE).add("POINT").add(lon).add(lat)
List<Object> response = connection.sync().dispatch(MyCommands.FENCE, new NestedMultiOutput<>(codec), args);
Command interfaces provide you a higher level of abstraction by declaring command methods on a Java interface. It's declared by a method signature that matches your command to invoke and less verbose than custom commands:
interface Tile38 {
@Command("NEARBY ?0 FENCE POINT ?1 ?2")
List<Object> nearByFence(String key, double lon, double lat);
}
RedisClient client = …
RedisCommandFactory factory = new RedisCommandFactory(client.connect());
Tile38 commands = factory.getCommands(Tile38.class);
Please note that I'm not familiar with Tile38 command responses. Therefore, all code uses List<Object>
which is the most generic return type.
BaseRedisCommands.dispatch(…)
.CommandOutput
.Upvotes: 10