当前位置: 首页>>代码示例>>Java>>正文


Java RedisClient类代码示例

本文整理汇总了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();
}
 
开发者ID:vert-x3,项目名称:vertx-redis-client,代码行数:26,代码来源:RedisClientTestBase.java

示例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();
        }
    });

}
 
开发者ID:sczyh30,项目名称:todo-backend-vert.x,代码行数:26,代码来源:TodoVerticle.java

示例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());
    }
  });
}
 
开发者ID:edgar615,项目名称:direwolves,代码行数:25,代码来源:RedisVerticle.java

示例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();
      }
    });
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:19,代码来源:RedisDataSourceExamples.java

示例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));
}
 
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:25,代码来源:RedisDataSourceTest.java

示例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());
		}
	});
}
 
开发者ID:aesteve,项目名称:vertx-feeds,代码行数:17,代码来源:WebServer.java

示例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...
      }
    });
  }
 
开发者ID:vert-x3,项目名称:vertx-redis-client,代码行数:21,代码来源:Examples.java

示例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();
}
 
开发者ID:vert-x3,项目名称:vertx-redis-client,代码行数:22,代码来源:RedisClientTestBase.java

示例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();
}
 
开发者ID:vert-x3,项目名称:vertx-redis-client,代码行数:23,代码来源:RedisClientTestBase.java

示例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);
        });
    });
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:23,代码来源:MyShoppingListVerticle.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:RedisClientUtils.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:RedisClientUtils.java

示例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;
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:15,代码来源:RedisDedup.java

示例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);
}
 
开发者ID:bpark,项目名称:chlorophytum-semantics,代码行数:9,代码来源:VertxLauncher.java

示例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;
}
 
开发者ID:kuangcao,项目名称:ninja-vertx-standalone,代码行数:12,代码来源:PubSub.java


注:本文中的io.vertx.redis.RedisClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。