Search in sources :

Example 36 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project pinpoint by naver.

the class JedisConstructorInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        if (!validate(target, args)) {
            return;
        }
        final StringBuilder endPoint = new StringBuilder();
        // first arg is host
        if (args[0] instanceof String) {
            endPoint.append(args[0]);
            // second arg is port
            if (args.length >= 2 && args[1] instanceof Integer) {
                endPoint.append(":").append(args[1]);
            } else {
                // set default port
                endPoint.append(":").append(6379);
            }
        } else if (args[0] instanceof URI) {
            final URI uri = (URI) args[0];
            endPoint.append(uri.getHost());
            endPoint.append(":");
            endPoint.append(uri.getPort());
        } else if (args[0] instanceof JedisShardInfo) {
            final JedisShardInfo info = (JedisShardInfo) args[0];
            endPoint.append(info.getHost());
            endPoint.append(":");
            endPoint.append(info.getPort());
        }
        ((EndPointAccessor) target)._$PINPOINT$_setEndPoint(endPoint.toString());
    } catch (Throwable t) {
        if (logger.isWarnEnabled()) {
            logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
        }
    }
}
Also used : EndPointAccessor(com.navercorp.pinpoint.plugin.redis.EndPointAccessor) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI)

Example 37 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class SSLJedisTest method connectWithShardInfoAndCustomSocketFactory.

/**
   * Tests opening an SSL/TLS connection to redis with a custom socket factory.
   */
@Test
public void connectWithShardInfoAndCustomSocketFactory() throws Exception {
    final URI uri = URI.create("rediss://localhost:6390");
    final SSLSocketFactory sslSocketFactory = createTrustStoreSslSocketFactory();
    final SSLParameters sslParameters = new SSLParameters();
    HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
    JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
    shardInfo.setPassword("foobared");
    Jedis jedis = new Jedis(shardInfo);
    jedis.get("foo");
    jedis.disconnect();
    jedis.close();
}
Also used : Jedis(redis.clients.jedis.Jedis) SSLParameters(javax.net.ssl.SSLParameters) JedisShardInfo(redis.clients.jedis.JedisShardInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URI(java.net.URI) HostnameVerifier(javax.net.ssl.HostnameVerifier) Test(org.junit.Test)

Example 38 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPipelineTest method setUp.

@Before
public void setUp() throws Exception {
    Jedis jedis = new Jedis(redis1.getHost(), redis1.getPort());
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();
    jedis = new Jedis(redis2.getHost(), redis2.getPort());
    jedis.auth("foobared");
    jedis.flushAll();
    jedis.disconnect();
    JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
    JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
    shardInfo1.setPassword("foobared");
    shardInfo2.setPassword("foobared");
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(shardInfo1);
    shards.add(shardInfo2);
    this.jedis = new ShardedJedis(shards);
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Before(org.junit.Before)

Example 39 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPipelineTest method testSyncWithNoCommandQueued.

@Test
public void testSyncWithNoCommandQueued() {
    JedisShardInfo shardInfo1 = new JedisShardInfo(redis1.getHost(), redis1.getPort());
    JedisShardInfo shardInfo2 = new JedisShardInfo(redis2.getHost(), redis2.getPort());
    shardInfo1.setPassword("foobared");
    shardInfo2.setPassword("foobared");
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(shardInfo1);
    shards.add(shardInfo2);
    ShardedJedis jedis2 = new ShardedJedis(shards);
    ShardedJedisPipeline pipeline = jedis2.pipelined();
    pipeline.sync();
    jedis2.close();
    jedis2 = new ShardedJedis(shards);
    pipeline = jedis2.pipelined();
    List<Object> resp = pipeline.syncAndReturnAll();
    assertTrue(resp.isEmpty());
    jedis2.close();
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) ArrayList(java.util.ArrayList) ShardedJedisPipeline(redis.clients.jedis.ShardedJedisPipeline) JedisShardInfo(redis.clients.jedis.JedisShardInfo) Test(org.junit.Test)

Example 40 with JedisShardInfo

use of redis.clients.jedis.JedisShardInfo in project jedis by xetorthio.

the class ShardedJedisPoolTest method startWithUrl.

@Test
public void startWithUrl() throws URISyntaxException {
    Jedis j = new Jedis("localhost", 6380);
    j.auth("foobared");
    j.set("foo", "bar");
    j = new Jedis("localhost", 6379);
    j.auth("foobared");
    j.set("foo", "bar");
    List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
    shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6380")));
    shards.add(new JedisShardInfo(new URI("redis://:foobared@localhost:6379")));
    GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
    ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
    Jedis[] jedises = pool.getResource().getAllShards().toArray(new Jedis[2]);
    Jedis jedis = jedises[0];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
    jedis = jedises[1];
    assertEquals("PONG", jedis.ping());
    assertEquals("bar", jedis.get("foo"));
}
Also used : ShardedJedis(redis.clients.jedis.ShardedJedis) Jedis(redis.clients.jedis.Jedis) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) URI(java.net.URI) Test(org.junit.Test)

Aggregations

JedisShardInfo (redis.clients.jedis.JedisShardInfo)52 Test (org.junit.Test)40 ShardedJedis (redis.clients.jedis.ShardedJedis)38 ArrayList (java.util.ArrayList)37 Jedis (redis.clients.jedis.Jedis)36 URI (java.net.URI)13 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)10 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)10 Sharded (redis.clients.util.Sharded)8 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 Before (org.junit.Before)6 SSLParameters (javax.net.ssl.SSLParameters)5 ShardedJedisPipeline (redis.clients.jedis.ShardedJedisPipeline)4 HostnameVerifier (javax.net.ssl.HostnameVerifier)3 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)3 JedisConnectionFactory (org.springframework.data.redis.connection.jedis.JedisConnectionFactory)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 CertificateException (java.security.cert.CertificateException)1