use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig 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 com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class RedisStandaloneTest method testStandaloneExample.
@Test
public void testStandaloneExample() {
long appId = 10122;
JedisPool jedisPool = null;
// 使用默认配置
// jedisPool = ClientBuilder.redisStandalone(appId).build();
/**
* 使用自定义配置
*/
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxIdle(GenericObjectPoolConfig.DEFAULT_MAX_IDLE * 3);
poolConfig.setMinIdle(GenericObjectPoolConfig.DEFAULT_MIN_IDLE * 2);
poolConfig.setJmxEnabled(true);
poolConfig.setMaxWaitMillis(3000);
jedisPool = ClientBuilder.redisStandalone(appId).setPoolConfig(poolConfig).setTimeout(2000).build();
Jedis jedis = jedisPool.getResource();
jedis.setnx("key2", "5");
assertEquals("10", jedis.incrBy("key2", 5));
jedis.close();
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class ShardedJedisPoolTest method startWithUrlString.
@Test
public void startWithUrlString() {
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("redis://:foobared@localhost:6380"));
shards.add(new JedisShardInfo("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"));
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class ShardedJedisPoolTest method shouldNotShareInstances.
@Test
public void shouldNotShareInstances() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(2);
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
ShardedJedis j1 = pool.getResource();
ShardedJedis j2 = pool.getResource();
assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project cachecloud by sohutv.
the class ShardedJedisPoolTest method checkResourceIsCloseable.
@Test
public void checkResourceIsCloseable() throws URISyntaxException {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
config.setBlockWhenExhausted(false);
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")));
ShardedJedisPool pool = new ShardedJedisPool(config, shards);
ShardedJedis jedis = pool.getResource();
try {
jedis.set("hello", "jedis");
} finally {
jedis.close();
}
ShardedJedis jedis2 = pool.getResource();
try {
assertEquals(jedis, jedis2);
} finally {
jedis2.close();
}
}
Aggregations