本文整理汇总了Java中io.vertx.redis.RedisClient类的典型用法代码示例。如果您正苦于以下问题:Java RedisClient类的具体用法?Java RedisClient怎么用?Java RedisClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RedisClient类属于io.vertx.redis包,在下文中一共展示了RedisClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAuth
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Test
//Note the try/finally is to ensure that the server is shutdown so other tests do not have to
//provide auth information
public void testAuth() throws Exception {
RedisServer server = RedisServer.builder().port(6381).setting("requirepass foobar").build();
server.start();
RedisOptions job = new RedisOptions()
.setHost("localhost")
.setPort(6381);
RedisClient rdx = RedisClient.create(vertx, job);
rdx.auth("barfoo", reply -> {
assertFalse(reply.succeeded());
rdx.auth("foobar", reply2 -> {
assertTrue(reply2.succeeded());
try {
server.stop();
} catch (Exception ignore) {
}
testComplete();
});
});
await();
}
示例2: initData
import io.vertx.redis.RedisClient; //导入依赖的package包/类
/**
* Init the redis client and save sample data
*/
private void initData() {
RedisOptions config;
// this is for OpenShift Redis Cartridge
String osPort = System.getenv("OPENSHIFT_REDIS_PORT");
String osHost = System.getenv("OPENSHIFT_REDIS_HOST");
if (osPort != null && osHost != null)
config = new RedisOptions()
.setHost(osHost).setPort(Integer.parseInt(osPort));
else
config = new RedisOptions().setHost(HOST);
redis = RedisClient.create(vertx, config);
redis.hset(REDIS_TODO_KEY, "98", Json.encodePrettily(
new Todo(98, "Something to do...", false, 1, "todo/ex")), res -> {
if (res.failed()) {
System.err.println("[Error]Redis service is not running!");
res.cause().printStackTrace();
}
});
}
示例3: start
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Override
public void start(Future<Void> startFuture) throws Exception {
Log.create(LOGGER)
.setEvent("redis.deploying")
.addData("config", config())
.info();
JsonObject redisConfig = config().getJsonObject("redis", new JsonObject());
RedisClient redisClient = RedisClientHelper.createShared(vertx, redisConfig);
redisClient.ping(ar -> {
if (ar.succeeded()) {
Log.create(LOGGER)
.setModule("redis")
.setEvent("redis.started.succeed")
.info();
startFuture.complete();
} else {
Log.create(LOGGER)
.setModule("redis")
.setEvent("redis.started.failed")
.error();
startFuture.fail(ar.cause());
}
});
}
示例4: example2
import io.vertx.redis.RedisClient; //导入依赖的package包/类
public void example2(ServiceDiscovery discovery) {
// Get the record
discovery.getRecord(
new JsonObject().put("name", "some-redis-data-source-service"), ar -> {
if (ar.succeeded() && ar.result() != null) {
// Retrieve the service reference
ServiceReference reference = discovery.getReference(ar.result());
// Retrieve the service instance
RedisClient client = reference.getAs(RedisClient.class);
// ...
// when done
reference.release();
}
});
}
示例5: testWithSugar
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Test
public void testWithSugar() throws InterruptedException {
Record record = RedisDataSource.createRecord("some-redis-data-source",
new JsonObject().put("url", "localhost"),
new JsonObject().put("database", "some-raw-data"));
discovery.publish(record, r -> {
});
await().until(() -> record.getRegistration() != null);
AtomicBoolean success = new AtomicBoolean();
RedisDataSource.getRedisClient(discovery,
new JsonObject().put("name", "some-redis-data-source"), ar -> {
RedisClient client = ar.result();
client.ping(ar1 -> {
if (ar1.succeeded()) {
client.close(ar2 ->
success.set(ar2.succeeded()));
}
});
});
await().untilAtomic(success, is(true));
}
示例6: start
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Override
public void start(Future<Void> future) {
mongo = new MongoDAO(MongoClient.createShared(vertx, config.getJsonObject("mongo")));
RedisDAO redis = new RedisDAO(RedisClient.create(vertx, RedisUtils.createRedisOptions(config.getJsonObject("redis"))));
authApi = new AuthenticationApi(mongo);
feedsApi = new FeedsApi(mongo, redis);
server = vertx.createHttpServer(createOptions());
server.requestHandler(createRouter()::accept);
server.listen(result -> {
if (result.succeeded()) {
future.complete();
} else {
future.fail(result.cause());
}
});
}
示例7: example3
import io.vertx.redis.RedisClient; //导入依赖的package包/类
public void example3(Vertx vertx) {
// register a handler for the incoming message the naming the Redis module will use is base address + '.' + redis channel
vertx.eventBus().<JsonObject>consumer("io.vertx.redis.channel1", received -> {
// do whatever you need to do with your message
JsonObject value = received.body().getJsonObject("value");
// the value is a JSON doc with the following properties
// channel - The channel to which this message was sent
// pattern - Pattern is present if you use psubscribe command and is the pattern that matched this message channel
// message - The message payload
});
RedisClient redis = RedisClient.create(vertx, new RedisOptions());
redis.subscribe("channel1", res -> {
if (res.succeeded()) {
// so something...
}
});
}
示例8: testDebugSegfault
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Test
public void testDebugSegfault() throws Exception {
RedisServer server = RedisServer.builder().port(6381).build();
server.start();
RedisOptions job = new RedisOptions()
.setHost("localhost")
.setPort(6381);
RedisClient rdx = RedisClient.create(vertx, job);
rdx.debugSegfault(reply -> {
// this should fail, since we crashed the server on purpose
assertTrue(reply.failed());
rdx.info(reply2 -> {
assertFalse(reply2.succeeded());
server.stop();
testComplete();
});
});
await();
}
示例9: testScriptkill
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Test
public void testScriptkill() throws Exception {
String inline = "while true do end";
redis.eval(inline, Collections.emptyList(), Collections.emptyList(), reply -> {
//server should be locked at this point
});
RedisOptions job = new RedisOptions()
.setHost("localhost")
.setPort(6379);
RedisClient rdx = RedisClient.create(vertx, job);
rdx.scriptKill(reply -> {
assertTrue(reply.succeeded());
rdx.info(reply2 -> {
assertTrue(reply2.succeeded());
testComplete();
});
});
await();
}
示例10: start
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
ServiceDiscovery.create(vertx, discovery -> {
RedisDataSource.getRedisClient(discovery, rec -> rec.getName().equals("redis"), ar -> {
if (ar.failed()) {
redis = RedisClient.create(vertx);
} else {
redis = ar.result();
}
router.get("/shopping").handler(this::getShoppingList);
router.route().handler(BodyHandler.create());
router.post("/shopping").handler(this::addItem);
router.get("/health").handler(rc -> rc.response().end("OK"));
vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
});
});
}
示例11: init
import io.vertx.redis.RedisClient; //导入依赖的package包/类
public static void init(Vertx vertx) throws InterruptedException {
RedisOptions redisOptions = new RedisOptions()
.setHost(PerfConfiguration.redisHost)
.setPort(PerfConfiguration.redisPort)
.setAuth(PerfConfiguration.redisPassword);
ClientPoolFactory<RedisClient> factory = () -> {
return RedisClient.create(vertx, redisOptions);
};
clientMgr = new ClientPoolManager<>(vertx, factory);
DeploymentOptions deployOptions = VertxUtils.createClientDeployOptions(clientMgr,
PerfConfiguration.redisClientCount);
VertxUtils.blockDeploy(vertx, ClientVerticle.class, deployOptions);
}
示例12: doQuery
import io.vertx.redis.RedisClient; //导入依赖的package包/类
private static CompletableFuture<String> doQuery(String id, boolean sync) {
CompletableFuture<String> future = new CompletableFuture<>();
RedisClient redisClient = clientMgr.findClientPool(sync);
RedisSession session = new RedisSession(redisClient, id, future);
session.query();
return future;
}
示例13: getRedisClient
import io.vertx.redis.RedisClient; //导入依赖的package包/类
private RedisClient getRedisClient() {
if (this.redisClient == null) {
final DedupConfig ddConfig = this.getDedupConfig();
final RedisOptions redisOptions = new RedisOptions();
redisOptions.setAddress(ddConfig.getServerURL());
redisOptions.setAuth(ddConfig.getSfdcPassword());
if (ddConfig.getPort() > 0) {
redisOptions.setPort(ddConfig.getPort());
}
this.redisClient = RedisClient.create(this.getVertx(), redisOptions);
}
return this.redisClient;
}
示例14: createRedisClient
import io.vertx.redis.RedisClient; //导入依赖的package包/类
@Produces
@RedisInstance
@ApplicationScoped
public RedisClient createRedisClient() {
RedisOptions config = new RedisOptions().setHost("192.168.2.108");
//RedisOptions config = new RedisOptions().setHost("192.168.56.2");
return RedisClient.create(vertx, config);
}
示例15: getInstance
import io.vertx.redis.RedisClient; //导入依赖的package包/类
private RedisClient getInstance() {
if (redis == null) {
synchronized (RedisClient.class) {
RedisOptions config = new RedisOptions()
.setHost(ninjaProperties.get(HOST_KEY))
.setPort(ninjaProperties.getInteger(PORT_KEY));
redis = RedisClient.create(vertx, config);
}
}
return redis;
}