forked from vert-x3/vertx-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRedisClientVerticle.java
36 lines (31 loc) · 989 Bytes
/
RedisClientVerticle.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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());
}
});
}
}