本文整理汇总了Java中redis.clients.jedis.JedisSentinelPool.destroy方法的典型用法代码示例。如果您正苦于以下问题:Java JedisSentinelPool.destroy方法的具体用法?Java JedisSentinelPool.destroy怎么用?Java JedisSentinelPool.destroy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.JedisSentinelPool
的用法示例。
在下文中一共展示了JedisSentinelPool.destroy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customClientName
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@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());
}
示例2: testSentinel
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@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();
}
示例3: initializeWithNotAvailableSentinelsShouldThrowException
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test(expected = JedisConnectionException.class)
public void initializeWithNotAvailableSentinelsShouldThrowException() {
Set<String> wrongSentinels = new HashSet<String>();
wrongSentinels.add(new HostAndPort("localhost", 65432).toString());
wrongSentinels.add(new HostAndPort("localhost", 65431).toString());
JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, wrongSentinels);
pool.destroy();
}
示例4: returnResourceShouldResetState
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@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");
pool.returnResource(jedis);
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
pool.returnBrokenResource(jedis2);
jedis2 = null;
}
} finally {
if (jedis2 != null) jedis2.close();
pool.destroy();
}
}
示例5: returnResourceShouldResetState
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@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();
}
}
示例6: addSentinel
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@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(appDesc, sentinelHost, masterName, masterHost, masterPort);
if (!isRun) {
return false;
}
return true;
}
示例7: test
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test
public void test() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
Set<String> sentinels = new HashSet<String>();
sentinels.add(new HostAndPort("192.168.0.36", 26379).toString());
JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,
config, 10000000);
Jedis jedis = pool.getResource();
Jedis jedis2 = null;
try {
jedis.set("hello", "jedis");
Transaction t = jedis.multi();
t.set("hello", "world");
pool.returnResource(jedis);
jedis2 = pool.getResource();
assertTrue(jedis == jedis2);
assertEquals("jedis", jedis2.get("hello"));
} catch (JedisConnectionException e) {
if (jedis2 != null) {
pool.returnBrokenResource(jedis2);
jedis2 = null;
}
} finally {
if (jedis2 != null)
pool.returnResource(jedis2);
pool.destroy();
}
}
示例8: main
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
public static void main(String[] args) {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
Set<String> sentinels = new HashSet<String>();
sentinels.add(new HostAndPort("192.168.0.36", 26379).toString());
JedisSentinelPool pool = new JedisSentinelPool("mymaster", sentinels,
config, 10000000);
Jedis jedis = pool.getResource();
jedis.set("hello", "world");
System.out.println(jedis.get("hello"));
pool.destroy();
}
示例9: initializeWithNotMonitoredMasterNameShouldThrowException
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
@Test(expected = JedisException.class)
public void initializeWithNotMonitoredMasterNameShouldThrowException() {
final String wrongMasterName = "wrongMasterName";
JedisSentinelPool pool = new JedisSentinelPool(wrongMasterName, sentinels);
pool.destroy();
}
示例10: disconnect
import redis.clients.jedis.JedisSentinelPool; //导入方法依赖的package包/类
public void disconnect() {
for (JedisSentinelPool jedis : getAllShards()) {
jedis.destroy();
}
}