1 Star 0 Fork 1

Batman/vertx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
RedisClientVerticle.java 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
package io.vertx.examples.redis;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.redis.RedisClient;
import io.vertx.redis.RedisOptions;
/**
* A verticle setting and reading a value in Redis.
*/
public class RedisClientVerticle extends AbstractVerticle {
@Override
public void start() throws Exception {
// If a config file is set, read the host and port.
String host = Vertx.currentContext().config().getString("host");
if (host == null) {
host = "127.0.0.1";
}
// Create the redis client
final RedisClient client = RedisClient.create(vertx,
new RedisOptions().setHost(host));
client.set("key", "value", r -> {
if (r.succeeded()) {
System.out.println("key stored");
client.get("key", s -> {
System.out.println("Retrieved value: " + s.result());
});
} else {
System.out.println("Connection or Operation Failed " + r.cause());
}
});
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/icecream/vertx-examples.git
git@gitee.com:icecream/vertx-examples.git
icecream
vertx-examples
vertx-examples
master

搜索帮助