Java Code Examples for redis.clients.jedis.Protocol#DEFAULT_PORT

The following examples show how to use redis.clients.jedis.Protocol#DEFAULT_PORT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisGelfSenderProvider.java    From xian with Apache License 2.0 6 votes vote down vote up
@Override
public GelfSender create(GelfSenderConfiguration configuration) throws IOException {

    String graylogHost = configuration.getHost();

    URI hostUri = URI.create(graylogHost);
    int port = hostUri.getPort();
    if (port <= 0) {
        port = configuration.getPort();
    }

    if (port <= 0) {
        port = Protocol.DEFAULT_PORT;
    }

    if (hostUri.getFragment() == null || hostUri.getFragment().trim().equals("")) {
        throw new IllegalArgumentException("Redis URI must specify fragment");
    }

    if (hostUri.getHost() == null) {
        throw new IllegalArgumentException("Redis URI must specify host");
    }

    Pool<Jedis> pool = RedisSenderPoolProvider.getJedisPool(hostUri, port);
    return new GelfREDISSender(pool, hostUri.getFragment(), configuration.getErrorReporter());
}
 
Example 2
Source File: RedisConnectionInfo.java    From kayenta with Apache License 2.0 6 votes vote down vote up
static RedisConnectionInfo parseConnectionUri(String connection) {
  URI redisConnection = URI.create(connection);
  String host = redisConnection.getHost();
  int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();
  int database = JedisURIHelper.getDBIndex(redisConnection);
  String password = JedisURIHelper.getPassword(redisConnection);
  boolean ssl = connection.startsWith(REDIS_SSL_SCHEME);

  return RedisConnectionInfo.builder()
      .host(host)
      .port(port)
      .database(database)
      .password(password)
      .ssl(ssl)
      .build();
}
 
Example 3
Source File: RedisMessenger.java    From LuckPerms with MIT License 6 votes vote down vote up
public void init(String address, String password, boolean ssl) {
    String[] addressSplit = address.split(":");
    String host = addressSplit[0];
    int port = addressSplit.length > 1 ? Integer.parseInt(addressSplit[1]) : Protocol.DEFAULT_PORT;

    this.jedisPool = new JedisPool(new JedisPoolConfig(), host, port, Protocol.DEFAULT_TIMEOUT, password, ssl);

    this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
        this.sub = new Subscription(this);
        try (Jedis jedis = this.jedisPool.getResource()) {
            jedis.subscribe(this.sub, CHANNEL);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
 
Example 4
Source File: JedisPoolFactory.java    From kork with Apache License 2.0 6 votes vote down vote up
public Pool<Jedis> build(
    String name, JedisDriverProperties properties, GenericObjectPoolConfig objectPoolConfig) {
  if (properties.connection == null || "".equals(properties.connection)) {
    throw new MissingRequiredConfiguration("Jedis client must have a connection defined");
  }

  URI redisConnection = URI.create(properties.connection);

  String host = redisConnection.getHost();
  int port = redisConnection.getPort() == -1 ? Protocol.DEFAULT_PORT : redisConnection.getPort();
  int database = parseDatabase(redisConnection.getPath());
  String password = parsePassword(redisConnection.getUserInfo());
  GenericObjectPoolConfig poolConfig =
      Optional.ofNullable(properties.poolConfig).orElse(objectPoolConfig);
  boolean isSSL = redisConnection.getScheme().equals("rediss");

  return new InstrumentedJedisPool(
      registry,
      // Pool name should always be "null", as setting this is incompat with some SaaS Redis
      // offerings
      new JedisPool(
          poolConfig, host, port, properties.timeoutMs, password, database, null, isSSL),
      name);
}
 
Example 5
Source File: JedisTest.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
@Test
public void connectWithShardInfo() {
  JedisShardInfo shardInfo = new JedisShardInfo("localhost", Protocol.DEFAULT_PORT);
  shardInfo.setPassword("foobared");
  Jedis jedis = new Jedis(shardInfo);
  jedis.get("foo");
}
 
Example 6
Source File: RedisEntityStoreMixin.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
@Override
public void activateService()
    throws Exception
{
    configuration.refresh();
    RedisEntityStoreConfiguration config = configuration.get();

    String host = config.host().get() == null ? DEFAULT_HOST : config.host().get();
    int port = config.port().get() == null ? Protocol.DEFAULT_PORT : config.port().get();
    int timeout = config.timeout().get() == null ? Protocol.DEFAULT_TIMEOUT : config.timeout().get();
    String password = config.password().get();
    int database = config.database().get() == null ? Protocol.DEFAULT_DATABASE : config.database().get();

    pool = new JedisPool( new JedisPoolConfig(), host, port, timeout, password, database );
}
 
Example 7
Source File: RedisClientConfiguration.java    From kork with Apache License 2.0 5 votes vote down vote up
private JedisCluster getJedisCluster(
    GenericObjectPoolConfig objectPoolConfig, ClientConfigurationWrapper config, URI cx) {
  int port = cx.getPort() == -1 ? Protocol.DEFAULT_PORT : cx.getPort();
  String password =
      (cx.getUserInfo() != null && cx.getUserInfo().contains(":"))
          ? cx.getUserInfo().substring(cx.getUserInfo().indexOf(":"))
          : null;

  return new JedisCluster(
      new HostAndPort(cx.getHost(), port),
      config.getTimeoutMs(),
      config.getTimeoutMs(),
      config.getMaxAttempts(),
      objectPoolConfig);
}
 
Example 8
Source File: RedisDataSet.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted(String distributedHost) {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxActive(getMaxActive());
    config.setMaxIdle(getMaxIdle());
    config.setMinIdle(getMinIdle());
    config.setMaxWait(getMaxWait());
    config.setWhenExhaustedAction((byte)getWhenExhaustedAction());
    config.setTestOnBorrow(getTestOnBorrow());
    config.setTestOnReturn(getTestOnReturn());
    config.setTestWhileIdle(getTestWhileIdle());
    config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
    config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
    config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
    config.setSoftMinEvictableIdleTimeMillis(getSoftMinEvictableIdleTimeMillis());

    int port = Protocol.DEFAULT_PORT;
    if(!JOrphanUtils.isBlank(this.port)) {
        port = Integer.parseInt(this.port);
    }
    int timeout = Protocol.DEFAULT_TIMEOUT;
    if(!JOrphanUtils.isBlank(this.timeout)) {
        timeout = Integer.parseInt(this.timeout);
    }
    int database = Protocol.DEFAULT_DATABASE;
    if(!JOrphanUtils.isBlank(this.database)) {
        database = Integer.parseInt(this.database);
    }
    String password = null;
    if(!JOrphanUtils.isBlank(this.password)) {
        password = this.password;
    }
    this.pool = new JedisPool(config, this.host, port, timeout, password, database);
}
 
Example 9
Source File: HostAndPortUtil.java    From cachecloud with Apache License 2.0 3 votes vote down vote up
public static List<HostAndPort> parseHosts(String envHosts,
    List<HostAndPort> existingHostsAndPorts) {

  if (null != envHosts && 0 < envHosts.length()) {

    String[] hostDefs = envHosts.split(",");

    if (null != hostDefs && 2 <= hostDefs.length) {

      List<HostAndPort> envHostsAndPorts = new ArrayList<HostAndPort>(hostDefs.length);

      for (String hostDef : hostDefs) {

        String[] hostAndPort = hostDef.split(":");

        if (null != hostAndPort && 2 == hostAndPort.length) {
          String host = hostAndPort[0];
          int port = Protocol.DEFAULT_PORT;

          try {
            port = Integer.parseInt(hostAndPort[1]);
          } catch (final NumberFormatException nfe) {
          }

          envHostsAndPorts.add(new HostAndPort(host, port));
        }
      }

      return envHostsAndPorts;
    }
  }

  return existingHostsAndPorts;
}