Skip to content

Java example (lettuce)

Lars Meijer edited this page Feb 21, 2017 · 5 revisions

lettuce project page

Install

Add the following dependency
Maven Central

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.

import com.lambdaworks.redis.RedisClient;
import com.lambdaworks.redis.api.StatefulRedisConnection;
import com.lambdaworks.redis.codec.StringCodec;
import com.lambdaworks.redis.output.StatusOutput;
import com.lambdaworks.redis.protocol.CommandArgs;
import com.lambdaworks.redis.protocol.CommandType;

/**
 * Example for using Tile38 in Java using lettuce version 5.0.1.Beta1
 */
public class example {

    public static void main(String[] args) {
        RedisClient client = RedisClient.create("redis://localhost:9851");
        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