Example #1
0
  protected void initializeRedis() {
    ConfigurationSection config = getConfig().getConfigurationSection("redis");
    String host = config.getString("host", "localhost");
    int port = config.getInt("port", 6379);
    int timeout = config.getInt("timeout", 5000);

    redisClient = new RedisClient(host, port);
    redisClient.setDefaultTimeout(timeout, TimeUnit.MILLISECONDS);

    log("Connecting to Redis at %s:%d", host, port);
    log("  Ping? %s", redis().ping());
    log("  Found %d keys", redis().dbsize());
  }
Example #2
0
  /**
   * Create a new client that connects to the supplied host and port. Connection attempts and
   * non-blocking commands will {@link #setDefaultTimeout timeout} after 60 seconds.
   *
   * @param host Server hostname.
   * @param port Server port.
   */
  public RedisClient(
      String host, int port, ExecutionContext executor, NioClientSocketChannelFactory factory) {
    this.executor = executor;
    // ExecutorService connectors = Executors.newFixedThreadPool(1);
    // ExecutorService workers    = Executors.newCachedThreadPool();
    // ClientSocketChannelFactory factory = new NioClientSocketChannelFactory(connectors, workers);

    InetSocketAddress addr = new InetSocketAddress(host, port);

    bootstrap = new ClientBootstrap(factory);
    bootstrap.setOption("remoteAddress", addr);

    setDefaultTimeout(60, TimeUnit.SECONDS);

    channels = new DefaultChannelGroup();
    timer = new HashedWheelTimer();
  }