Skip to content

Instantly share code, notes, and snippets.

@guyroyse
Created March 11, 2020 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guyroyse/6215f2ed867785c6a43fc674807a4ff9 to your computer and use it in GitHub Desktop.
Save guyroyse/6215f2ed867785c6a43fc674807a4ff9 to your computer and use it in GitHub Desktop.
package com.guyroyse.blogs.lettucevsjedis;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
public class LettuceAsync {
private static final String YOUR_CONNECTION_STRING = "redis://:foobared@yourserver:6379/0";
public static void main(String[] args) {
RedisClient redisClient = RedisClient.create(YOUR_CONNECTION_STRING);
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisAsyncCommands<String, String> async = connection.async();
final String[] result = new String[1];
async.set("foo", "bar")
.thenComposeAsync(ok -> async.get("foo"))
.thenAccept(s -> result[0] = s)
.toCompletableFuture()
.join();
connection.close();
redisClient.shutdown();
System.out.println(result[0]); // "bar"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment