Java Code Examples for redis.clients.jedis.JedisPoolConfig#setMaxActive()

The following examples show how to use redis.clients.jedis.JedisPoolConfig#setMaxActive() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisClient.java    From Redis_Learning with Apache License 2.0 6 votes vote down vote up
/**
 * ��ʼ����Ƭ��
 */
private void initialShardedPool() {
	// �ػ�������
	JedisPoolConfig config = new JedisPoolConfig();
	config.setMaxActive(20);
	config.setMaxIdle(5);
	config.setMaxWait(1000l);
	config.setTestOnBorrow(false);

	List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
	JedisShardInfo infoA = new JedisShardInfo(ADDR, PORT);
	infoA.setPassword("redis");
	shards.add(infoA);
	// ���Dz��� ��ʱ���������ķ������������ӷ���������
	// JedisShardInfo infoB = new JedisShardInfo(SUB_ADDR, PORT2);
	// infoB.setPassword("redis");
	// shards.add(infoB);
	// shards = Arrays.asList(infoA,infoB);
	shardedJedisPool = new ShardedJedisPool(config, shards,
			Hashing.MURMUR_HASH, ShardedJedis.DEFAULT_KEY_TAG_PATTERN);
}
 
Example 2
Source File: JedisClientHelper.java    From pinlater with Apache License 2.0 6 votes vote down vote up
public JedisPool createClient(RedisClientConfig redisClientConfig, EndPoint endPoint) {
  JedisPoolConfig config = new JedisPoolConfig();
  config.setMaxWait(redisClientConfig.getMaxWaitMillis());
  config.setMaxActive(redisClientConfig.getNumConnections());
  config.setMaxIdle(redisClientConfig.getNumConnections());
  // Deal with idle connection eviction.
  config.setTestOnBorrow(false);
  config.setTestOnReturn(false);
  config.setTestWhileIdle(true);
  config.setMinEvictableIdleTimeMillis(5 * 60 * 1000);
  config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000);
  config.setNumTestsPerEvictionRun(redisClientConfig.getNumConnections());
  JedisPool jedisPool = new JedisPool(
      config, endPoint.host, endPoint.port, redisClientConfig.getSocketTimeoutMillis());
  return jedisPool;
}
 
Example 3
Source File: BillingJedis.java    From gameserver with Apache License 2.0 6 votes vote down vote up
private BillingJedis() {
	JedisPoolConfig poolConfig = new JedisPoolConfig();
	poolConfig.setMaxActive(5);
	poolConfig.setMinIdle(5);
	
	int i=1;
	while ( true ) {
		String key = StringUtil.concat(prefix, i++);
		String redisId = GlobalConfig.getInstance().getStringProperty(key);
		if ( redisId == null ) {
			break;
		} else {
			String[] redisHostPort = StringUtil.splitMachineId(redisId);
			String jedisHost = redisHostPort[0];
			int jedisPort = StringUtil.toInt(redisHostPort[1], 6379);
			Jedis jedis = new JedisAdapter(jedisHost, jedisPort, poolConfig);
			logger.info("Connect to {} {}", new Object[]{key, redisId});
			jedises.add(jedis);
		}
	}
}
 
Example 4
Source File: RedisClient.java    From Redis_Learning with Apache License 2.0 5 votes vote down vote up
/**
 * ��ʼ������Ƭ��
 */
private void initialPool() {
	// �ػ�������
	JedisPoolConfig config = new JedisPoolConfig();
	config.setMaxActive(MAX_ACTIVE);
	config.setMaxIdle(MAX_IDLE);
	config.setMaxWait(MAX_WAIT);
	config.setTestOnBorrow(TEST_ON_BORROW);

	jedisPool = new JedisPool(config, ADDR, PORT, TIMEOUT, PASSWORD);
}
 
Example 5
Source File: RedisPools.java    From pinlater with Apache License 2.0 5 votes vote down vote up
private static JedisPool createRedisPool(
    String host, int port, int poolSize, int maxWaitMillis, int socketTimeoutMillis) {
  JedisPoolConfig config = new JedisPoolConfig();
  config.setMaxWait(maxWaitMillis);
  config.setMaxActive(poolSize);
  config.setMaxIdle(poolSize);
  // Deal with idle connection eviction.
  config.setTestOnBorrow(false);
  config.setTestOnReturn(false);
  config.setTestWhileIdle(true);
  config.setMinEvictableIdleTimeMillis(5 * 60 * 1000);
  config.setTimeBetweenEvictionRunsMillis(3 * 60 * 1000);
  config.setNumTestsPerEvictionRun(poolSize);

  JedisPool pool = new JedisPool(config, host, port, socketTimeoutMillis);
  // Force connection pool initialization.
  Jedis jedis = null;
  try {
    jedis = pool.getResource();
  } catch (JedisConnectionException e) {
    LOG.error(
        String.format("Failed to get a redis connection when creating redis pool, "
            + "host: %s, port: %d", host, port),
        e);
  } finally {
    pool.returnResource(jedis);
  }
  return pool;
}
 
Example 6
Source File: RedisDataSet.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void testStarted(String distributedHost) {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxActive(getMaxActive());
    config.setMaxIdle(getMaxIdle());
    config.setMinIdle(getMinIdle());
    config.setMaxWait(getMaxWait());
    config.setWhenExhaustedAction((byte)getWhenExhaustedAction());
    config.setTestOnBorrow(getTestOnBorrow());
    config.setTestOnReturn(getTestOnReturn());
    config.setTestWhileIdle(getTestWhileIdle());
    config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
    config.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun());
    config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
    config.setSoftMinEvictableIdleTimeMillis(getSoftMinEvictableIdleTimeMillis());

    int port = Protocol.DEFAULT_PORT;
    if(!JOrphanUtils.isBlank(this.port)) {
        port = Integer.parseInt(this.port);
    }
    int timeout = Protocol.DEFAULT_TIMEOUT;
    if(!JOrphanUtils.isBlank(this.timeout)) {
        timeout = Integer.parseInt(this.timeout);
    }
    int database = Protocol.DEFAULT_DATABASE;
    if(!JOrphanUtils.isBlank(this.database)) {
        database = Integer.parseInt(this.database);
    }
    String password = null;
    if(!JOrphanUtils.isBlank(this.password)) {
        password = this.password;
    }
    this.pool = new JedisPool(config, this.host, port, timeout, password, database);
}
 
Example 7
Source File: SpringDataRedis.java    From howsun-javaee-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(String[] args) {
	JedisShardInfo jedisShardInfo1 = new JedisShardInfo(ip1);
	jedisShardInfo1.setPassword(JedisConstant.password);
	JedisShardInfo jedisShardInfo2 = new JedisShardInfo(ip2);
	jedisShardInfo2.setPassword(JedisConstant.password);

	List<JedisShardInfo> jedisShardInfos = new ArrayList<JedisShardInfo>();
	jedisShardInfos.add(jedisShardInfo1);
	jedisShardInfos.add(jedisShardInfo2);

	JedisPoolConfig poolConfig = new JedisPoolConfig();
	poolConfig.setMaxActive(JedisConstant.maxActive);
	poolConfig.setMaxIdle(JedisConstant.maxIdle);
	poolConfig.setMaxWait(JedisConstant.maxWait);
	poolConfig.setTestOnBorrow(JedisConstant.testOnBorrow);
	poolConfig.setTestOnReturn(JedisConstant.testOnReturn);


	ShardedJedisPool shardedJedisPool = new ShardedJedisPool(poolConfig, jedisShardInfos);

	JedisConnectionFactory factory = new JedisConnectionFactory(jedisShardInfo1);
	StringRedisTemplate template = new StringRedisTemplate(factory);
	for (int i = 0; i < 2000; i++) {
		String key = "howsun_" + i;
		BoundValueOperations<String, String> v = template.boundValueOps(key);
		//jedis.set(key, UUID.randomUUID().toString());
		System.out.println(key + "\t" + v.get() + "\t" + factory.getHostName());
	}

}