Skip to content

Java example (lettuce)

Josh Baker edited this page Feb 22, 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;
mport com.lambdaworks.redis.api.sync.RedisCommands;

/**
 * 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