use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig in project cas by apereo.
the class RedisObjectFactory method getRedisPoolClientConfig.
private static LettucePoolingClientConfiguration getRedisPoolClientConfig(final BaseRedisProperties redis, final boolean cluster, final CasSSLContext casSslContext) {
val poolingClientConfig = LettucePoolingClientConfiguration.builder();
if (redis.isUseSsl()) {
poolingClientConfig.useSsl();
LOGGER.trace("Redis configuration: SSL connections are enabled");
}
if (redis.getReadFrom() != null) {
poolingClientConfig.readFrom(ReadFrom.valueOf(redis.getReadFrom().name()));
LOGGER.debug("Redis configuration: readFrom property is set to [{}]", redis.getReadFrom());
}
if (StringUtils.hasText(redis.getTimeout())) {
val commandTimeout = Beans.newDuration(redis.getTimeout());
val commandTimeoutMillis = commandTimeout.toMillis();
if (commandTimeoutMillis > 0) {
poolingClientConfig.commandTimeout(Duration.ofMillis(commandTimeoutMillis));
LOGGER.trace("Redis configuration: commandTimeout is set to [{}]ms", commandTimeoutMillis);
}
}
poolingClientConfig.clientOptions(createClientOptions(redis, cluster, casSslContext));
val pool = redis.getPool();
if (pool != null && pool.isEnabled()) {
val config = new GenericObjectPoolConfig();
config.setMaxTotal(pool.getMaxActive());
config.setMaxIdle(pool.getMaxIdle());
config.setMinIdle(pool.getMinIdle());
config.setMaxWaitMillis(pool.getMaxWait());
config.setLifo(pool.isLifo());
config.setFairness(pool.isFairness());
config.setTestWhileIdle(pool.isTestWhileIdle());
config.setTestOnBorrow(pool.isTestOnBorrow());
config.setTestOnReturn(pool.isTestOnReturn());
config.setTestOnCreate(pool.isTestOnCreate());
if (pool.getMinEvictableIdleTimeMillis() > 0) {
config.setMinEvictableIdleTime(Duration.ofMillis(pool.getMinEvictableIdleTimeMillis()));
}
if (pool.getNumTestsPerEvictionRun() > 0) {
config.setNumTestsPerEvictionRun(pool.getNumTestsPerEvictionRun());
}
if (pool.getSoftMinEvictableIdleTimeMillis() > 0) {
config.setSoftMinEvictableIdleTime(Duration.ofMillis(pool.getSoftMinEvictableIdleTimeMillis()));
}
poolingClientConfig.poolConfig(config);
LOGGER.trace("Redis configuration: the pool is configured to [{}]", config);
}
return poolingClientConfig.build();
}
use of org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig 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 org.datanucleus.store.rdbms.datasource.dbcp2.pool2.impl.GenericObjectPoolConfig 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 org.datanucleus.store.rdbms.datasource.dbcp2.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 org.datanucleus.store.rdbms.datasource.dbcp2.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();
}
Aggregations