use of redis.clients.jedis.JedisSentinelPool in project cachecloud by sohutv.
the class JedisSentinelPoolTest method customClientName.
@Test
public void customClientName() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 0, "my_shiny_client_name");
Jedis jedis = pool.getResource();
try {
assertEquals("my_shiny_client_name", jedis.clientGetname());
} finally {
jedis.close();
pool.destroy();
}
assertTrue(pool.isClosed());
}
use of redis.clients.jedis.JedisSentinelPool in project cachecloud by sohutv.
the class JedisSentinelPoolTest method checkCloseableConnections.
@Test
public void checkCloseableConnections() throws Exception {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
Jedis jedis = pool.getResource();
jedis.auth("foobared");
jedis.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
jedis.close();
pool.close();
assertTrue(pool.isClosed());
}
use of redis.clients.jedis.JedisSentinelPool in project cachecloud by sohutv.
the class JedisSentinelPoolTest method returnResourceShouldResetState.
@Test
public void returnResourceShouldResetState() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels, config, 1000, "foobared", 2);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
jedis.close();
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
jedis2 = null;
}
} finally {
jedis2.close();
pool.destroy();
}
}
use of redis.clients.jedis.JedisSentinelPool in project cachecloud by sohutv.
the class RedisDeployCenterImpl method addSentinel.
@Override
public boolean addSentinel(long appId, String sentinelHost) {
AppDesc appDesc = appDao.getAppDescById(appId);
JedisSentinelPool jedisSentinelPool = redisCenter.getJedisSentinelPool(appDesc);
if (jedisSentinelPool == null) {
return false;
}
List<InstanceInfo> instanceInfos = instanceDao.getInstListByAppId(appId);
String masterName = null;
for (Iterator<InstanceInfo> i = instanceInfos.iterator(); i.hasNext(); ) {
InstanceInfo instanceInfo = i.next();
if (instanceInfo.getType() != ConstUtils.CACHE_REDIS_SENTINEL) {
i.remove();
continue;
}
if (masterName == null && StringUtils.isNotBlank(instanceInfo.getCmd())) {
masterName = instanceInfo.getCmd();
}
}
Jedis jedis = null;
String masterHost = null;
Integer masterPort = null;
try {
jedis = jedisSentinelPool.getResource();
masterHost = jedis.getClient().getHost();
masterPort = jedis.getClient().getPort();
} catch (Exception e) {
logger.error(e.getMessage(), e);
} finally {
jedis.close();
jedisSentinelPool.destroy();
}
boolean isRun = runSentinel(sentinelHost, masterName, masterHost, masterPort, appId);
if (!isRun) {
return false;
}
return true;
}
use of redis.clients.jedis.JedisSentinelPool in project cachecloud by sohutv.
the class RedisSentinelTest method testSentinel.
@Test
public void testSentinel() {
JedisSentinelPool sentinelPool = ClientBuilder.redisSentinel(appId).setConnectionTimeout(2000).setSoTimeout(1000).build();
HostAndPort currentHostMaster = sentinelPool.getCurrentHostMaster();
logger.info("current master: {}", currentHostMaster.toString());
Jedis jedis = sentinelPool.getResource();
for (int i = 0; i < 10; i++) {
jedis.lpush("mylist", "list-" + i);
}
jedis.close();
sentinelPool.destroy();
}
Aggregations