您的位置:首页 > 数据库 > Redis

redis lettuce 初涉1

2016-07-21 16:21 573 查看
初步接触 Lettuce  附上一段最简单的异步代码:

需要jar包 lettuce-4.2.1.Final-shaded.jar

RedisClient redisClient = RedisClient.create("redis://password@127.0.0.1:6379/0");// 新建客户端
StatefulRedisConnection<String, String> connection = redisClient.connect();// 连接

RedisAsyncCommands<String, String> asynCommands = connection.async();// 异步操作

RedisFuture<String> future = asynCommands.get("key");// 使用future
future.thenAccept((e) -> System.out.println(e)); // 接收到数据时 执行
// 执行其他操作

// 关闭连接
connection.close();
redisClient.shutdown();

参考网址:https://github.com/mp911de/lettuce/wiki/Asynchronous-API-%284.0%29

留作参考。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  redis lettuce async future