本文整理汇总了Java中io.vertx.redis.RedisClient.create方法的典型用法代码示例。如果您正苦于以下问题:Java RedisClient.create方法的具体用法?Java RedisClient.create怎么用?Java RedisClient.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.redis.RedisClient
的用法示例。
在下文中一共展示了RedisClient.create方法的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> 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());
}
});
}
示例4: 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...
}
});
}
示例5: 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();
}
示例6: 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();
}
示例7: 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);
}
示例8: 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;
}
示例9: 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);
}
示例10: 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;
}
示例11: retrieve
import io.vertx.redis.RedisClient; //导入方法依赖的package包/类
/**
* Creates a Redis client for the service.
*
* @return the Redis client, configured to access the service
*/
@Override
protected RedisClient retrieve() {
JsonObject result = record().getMetadata().copy();
result.mergeIn(record().getLocation());
if (config != null) {
result.mergeIn(config);
}
return RedisClient.create(vertx, new RedisOptions(result));
}
示例12: setUp
import io.vertx.redis.RedisClient; //导入方法依赖的package包/类
@Before
public void setUp(TestContext tc) throws IOException {
vertx = Vertx.vertx();
vertx.exceptionHandler(tc.exceptionHandler());
redisServer = new RedisServer(6379);
redisServer.start();
testRedisClient = RedisClient.create(vertx,
new RedisOptions().setHost("localhost").setPort(6379));
}
示例13: getRedisClient
import io.vertx.redis.RedisClient; //导入方法依赖的package包/类
public RedisClient getRedisClient() {
if (redisClient == null) {
redisClient = RedisClient.create(getVertx(), getRedisOptions());
}
return redisClient;
}
示例14: start
import io.vertx.redis.RedisClient; //导入方法依赖的package包/类
@Override
public void start(Future<Void> future) {
mongo = MongoClient.createShared(vertx, config.getJsonObject("mongo"));
redis = new RedisDAO(RedisClient.create(vertx, RedisUtils.createRedisOptions(config.getJsonObject("redis"))));
fetchFeeds();
future.complete();
}
示例15: example2
import io.vertx.redis.RedisClient; //导入方法依赖的package包/类
public void example2(Vertx vertx) {
RedisClient redis = RedisClient.create(vertx, new RedisOptions());
redis.get("mykey", res -> {
if (res.succeeded()) {
// so something...
}
});
}