Search in sources :

Example 1 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project springboot-demo by small-rose.

the class JedisConfig method jedisPoolConfig.

/**
 * 初始化jedis连接池
 */
@Bean
public ShardedJedisPool jedisPoolConfig() {
    // 创建jedis池配置实例
    GenericObjectPoolConfig jedisPoolConfig = new JedisPoolConfig();
    // 设连接池最大连接数
    jedisPoolConfig.setMaxTotal(Integer.parseInt(maxActive));
    // 连接池中的最大空闲连接
    jedisPoolConfig.setMaxIdle(Integer.parseInt(maxIdle));
    // 连接池最大阻塞等待时间
    // jedisPoolConfig.setMaxWaitMillis(Long.valueOf(maxWait.substring(0, maxWait.length() - 2)));
    jedisPoolConfig.setMaxWaitMillis(Long.valueOf(maxWait));
    // #jedis调用borrowObject方法时,是否进行有效检查
    jedisPoolConfig.setTestOnBorrow(Boolean.valueOf(true));
    // #jedis调用returnObject方法时,是否进行有效检查
    jedisPoolConfig.setTestOnReturn(Boolean.valueOf(true));
    List<JedisShardInfo> jdsInfoList = new ArrayList<JedisShardInfo>(2);
    JedisShardInfo jedisShardInfo = new JedisShardInfo(host, port);
    jdsInfoList.add(jedisShardInfo);
    ShardedJedisPool pool = new ShardedJedisPool(jedisPoolConfig, jdsInfoList, Hashing.MURMUR_HASH, Sharded.DEFAULT_KEY_TAG_PATTERN);
    return pool;
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project yuzhouwan by asdf2014.

the class JedisListHashTest method init.

private void init() {
    List<JedisShardInfo> shards = new ArrayList<>();
    JedisShardInfo si = new JedisShardInfo("localhost", 6379);
    si.setPassword("asdf");
    shards.add(si);
    si = new JedisShardInfo("localhost", 6380);
    si.setPassword("asdf");
    shards.add(si);
    pool = new ShardedJedisPool(new GenericObjectPoolConfig(), shards);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) ShardedJedisPool(redis.clients.jedis.ShardedJedisPool) ArrayList(java.util.ArrayList) JedisShardInfo(redis.clients.jedis.JedisShardInfo)

Example 3 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project LinkAgent by shulieTech.

the class JedisSentinelFactory method createMediator.

@Override
public RedisClientMediator createMediator(Object obj, ShadowRedisConfig shadowConfig) {
    model.cachePressureNode(shadowConfig);
    RedisClientMediator mediator = null;
    if (Jedis.class.isAssignableFrom(obj.getClass())) {
        Object datasource = Reflect.on(obj).get("dataSource");
        if (datasource != null && JedisSentinelPool.class.isAssignableFrom(datasource.getClass())) {
            JedisSentinelPool pressureJedisPool = null;
            String masterName = shadowConfig.getMaster();
            Set nodes = new HashSet(shadowConfig.getNodeNums());
            String password = shadowConfig.getPassword();
            GenericObjectPoolConfig poolConfig = Reflect.on(datasource).get("poolConfig");
            password = StringUtil.isEmpty(password) ? null : password;
            int database = shadowConfig.getDatabase() == null ? 0 : shadowConfig.getDatabase();
            pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig, 2000, password, database);
            /* else if (StringUtil.isEmpty(password)) {
                    pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig);

                } else {
                    pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig, password);
                }*/
            mediator = new RedisClientMediator<JedisSentinelPool>(pressureJedisPool, (JedisSentinelPool) datasource, true);
        }
    }
    return mediator;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) RedisClientMediator(com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool) HashSet(java.util.HashSet)

Example 4 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project flink-connector-redis by jeff-zou.

the class RedisCommandsContainerBuilder method build.

/**
 * Builds container for Redis Cluster environment.
 *
 * @param jedisClusterConfig configuration for JedisCluster
 * @return container for Redis Cluster environment
 * @throws NullPointerException if jedisClusterConfig is null
 */
public static RedisCommandsContainer build(FlinkJedisClusterConfig jedisClusterConfig) {
    Objects.requireNonNull(jedisClusterConfig, "Redis cluster config should not be Null");
    GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
    genericObjectPoolConfig.setMaxIdle(jedisClusterConfig.getMaxIdle());
    genericObjectPoolConfig.setMaxTotal(jedisClusterConfig.getMaxTotal());
    genericObjectPoolConfig.setMinIdle(jedisClusterConfig.getMinIdle());
    JedisCluster jedisCluster = new JedisCluster(jedisClusterConfig.getNodes(), jedisClusterConfig.getConnectionTimeout(), jedisClusterConfig.getConnectionTimeout(), jedisClusterConfig.getMaxRedirections(), jedisClusterConfig.getPassword(), genericObjectPoolConfig);
    return new RedisClusterContainer(jedisCluster);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisCluster(redis.clients.jedis.JedisCluster)

Example 5 with GenericObjectPoolConfig

use of com.frameworkset.commons.pool2.impl.GenericObjectPoolConfig in project flink-connector-redis by jeff-zou.

the class RedisCommandsContainerBuilder method build.

/**
 * Builds container for Redis Sentinel environment.
 *
 * @param jedisSentinelConfig configuration for JedisSentinel
 * @return container for Redis sentinel environment
 * @throws NullPointerException if jedisSentinelConfig is null
 */
public static RedisCommandsContainer build(FlinkJedisSentinelConfig jedisSentinelConfig) {
    Objects.requireNonNull(jedisSentinelConfig, "Redis sentinel config should not be Null");
    GenericObjectPoolConfig genericObjectPoolConfig = new GenericObjectPoolConfig();
    genericObjectPoolConfig.setMaxIdle(jedisSentinelConfig.getMaxIdle());
    genericObjectPoolConfig.setMaxTotal(jedisSentinelConfig.getMaxTotal());
    genericObjectPoolConfig.setMinIdle(jedisSentinelConfig.getMinIdle());
    JedisSentinelPool jedisSentinelPool = new JedisSentinelPool(jedisSentinelConfig.getMasterName(), jedisSentinelConfig.getSentinels(), genericObjectPoolConfig, jedisSentinelConfig.getConnectionTimeout(), jedisSentinelConfig.getSoTimeout(), jedisSentinelConfig.getPassword(), jedisSentinelConfig.getDatabase());
    return new RedisContainer(jedisSentinelPool);
}
Also used : GenericObjectPoolConfig(org.apache.commons.pool2.impl.GenericObjectPoolConfig) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool)

Aggregations

GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)222 Test (org.junit.Test)82 Jedis (redis.clients.jedis.Jedis)44 ShardedJedisPool (redis.clients.jedis.ShardedJedisPool)43 ShardedJedis (redis.clients.jedis.ShardedJedis)41 JedisPool (redis.clients.jedis.JedisPool)37 GenericObjectPool (org.apache.commons.pool2.impl.GenericObjectPool)32 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)21 Bean (org.springframework.context.annotation.Bean)20 ArrayList (java.util.ArrayList)17 JedisShardInfo (redis.clients.jedis.JedisShardInfo)17 Test (org.junit.jupiter.api.Test)15 URI (java.net.URI)12 LettuceConnectionFactory (org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory)12 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)12 RedisStandaloneConfiguration (org.springframework.data.redis.connection.RedisStandaloneConfiguration)11 IOException (java.io.IOException)10 Test (org.testng.annotations.Test)10 PooledObject (org.apache.commons.pool2.PooledObject)9 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)9