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
Overview This article is an introduction to Lettuce, a Redis Java client. Redis is an in-memory key-value store that can be used as a database, cache or message broker. Data is added, queried, modified, and deleted with commands that operate on keys in Redis' in-memory data structure.
Synchronous Commands Similar to Jedis, Lettuce provides a complete Redis command set in the form of methods. However, Lettuce implements both synchronous and asynchronous versions. We’ll look at the synchronous version briefly, and then use the asynchronous implementation for the rest of the tutorial.
RedisAdvancedClusterCommands holds the set of Redis commands supported by the cluster, routing them to the instance that holds the key. A complete specification is available here. 10. Conclusion In this tutorial, we looked at how to use Lettuce to connect and query a Redis server from within our application.
Connecting to a Server RedisClient redisClient = RedisClient .create ( "redis://password@localhost:6379/" ); StatefulRedisConnection<String, String> connection = redisClient.connect ();
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
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With