Created
March 11, 2020 23:06
-
-
Save guyroyse/6215f2ed867785c6a43fc674807a4ff9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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