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);
}
}
}
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();
}
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);
}
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();
}
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"));
}
Aggregations