Skip to content

Java example (lettuce)

Josh Baker edited this page Mar 10, 2022 · 5 revisions

lettuce project page

Example

All Tile38 commands should be sent using the .dispatch(...) method of either the synchronous, asynchronous or reactive API. Please refer to the official documentation for more information.

package example;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.codec.StringCodec;
import io.lettuce.core.output.StatusOutput;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;

public class Example {
  public static void main(String[] args) {
        RedisURI uri = RedisURI.Builder.redis("localhost", 9851).build();
        RedisClient client = RedisClient.create(uri);
        StatefulRedisConnection<String, String> connection = client.connect();
        RedisCommands<String, String> sync = connection.sync();

        StringCodec codec = StringCodec.UTF8;
        sync.dispatch(CommandType.SET,
                new StatusOutput<>(codec), new CommandArgs<>(codec)
                        .add("fleet")
                        .add("truck1")
                        .add("POINT")
                        .add(33L)
                        .add(-115L));

        String result = sync.dispatch(CommandType.GET,
                new StatusOutput<>(codec), new CommandArgs<>(codec)
                        .add("fleet")
                        .add("truck1"));

        System.out.println(result);
    }
}
Clone this wiki locally