當前位置: 首頁>>代碼示例>>Java>>正文


Java JedisPoolConfig.setTestOnBorrow方法代碼示例

本文整理匯總了Java中redis.clients.jedis.JedisPoolConfig.setTestOnBorrow方法的典型用法代碼示例。如果您正苦於以下問題:Java JedisPoolConfig.setTestOnBorrow方法的具體用法?Java JedisPoolConfig.setTestOnBorrow怎麽用?Java JedisPoolConfig.setTestOnBorrow使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.JedisPoolConfig的用法示例。


在下文中一共展示了JedisPoolConfig.setTestOnBorrow方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Client

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
/**
 * Create a new client to a RediSearch index
 * @param indexName the name of the index we are connecting to or creating
 * @param host the redis host
 * @param port the redis pot
 */
public Client(String indexName, String host, int port, int timeout, int poolSize) {
    JedisPoolConfig conf = new JedisPoolConfig();
    conf.setMaxTotal(poolSize);
    conf.setTestOnBorrow(false);
    conf.setTestOnReturn(false);
    conf.setTestOnCreate(false);
    conf.setTestWhileIdle(false);
    conf.setMinEvictableIdleTimeMillis(60000);
    conf.setTimeBetweenEvictionRunsMillis(30000);
    conf.setNumTestsPerEvictionRun(-1);
    conf.setFairness(true);

    pool = new JedisPool(conf, host, port, timeout);

    this.indexName = indexName;
    this.commands = new Commands.SingleNodeCommands();
}
 
開發者ID:RedisLabs,項目名稱:JRediSearch,代碼行數:24,代碼來源:Client.java

示例2: JedisHolder

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
private JedisHolder(SpiderConfig config) {
    this.config = config;
    this.redisIp = this.config.getRedisIp();
    this.redisPort = this.config.getRedisPort();
    JedisPoolConfig config1 = new JedisPoolConfig();
    config1.setLifo(true);
    config1.setMaxIdle(8);
    config1.setMaxTotal(8);
    config1.setMaxWaitMillis(-1);
    config1.setMinEvictableIdleTimeMillis(1800000);
    config1.setMinIdle(0);
    config1.setNumTestsPerEvictionRun(3);
    config1.setSoftMinEvictableIdleTimeMillis(1800000);
    config1.setTestOnBorrow(false);
    config1.setTestWhileIdle(false);
    config1.setTimeBetweenEvictionRunsMillis(-1);

    this.jedisPool = new JedisPool(config1, this.redisIp, this.redisPort, 3000);
}
 
開發者ID:StevenKin,項目名稱:ZhihuQuestionsSpider,代碼行數:20,代碼來源:JedisHolder.java

示例3: createJedisPoolConfig

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
private static JedisPoolConfig createJedisPoolConfig(Builder builder) {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(builder.maxTotal);
    config.setMaxIdle(builder.maxIdle);
    config.setMinIdle(builder.minIdle);
    config.setLifo(builder.lifo);
    config.setFairness(builder.fairness);
    config.setMaxWaitMillis(builder.maxWaitMillis);
    config.setMinEvictableIdleTimeMillis(builder.minEvictableIdleTimeMillis);
    config.setSoftMinEvictableIdleTimeMillis(builder.softMinEvictableIdleTimeMillis);
    config.setNumTestsPerEvictionRun(builder.numTestsPerEvictionRun);
    config.setTestOnCreate(builder.testOnCreate);
    config.setTestOnBorrow(builder.testOnBorrow);
    config.setTestOnReturn(builder.testOnReturn);
    config.setTestWhileIdle(builder.testWhileIdle);
    config.setTimeBetweenEvictionRunsMillis(builder.timeBetweenEvictionRunsMillis);
    config.setEvictionPolicyClassName(builder.evictionPolicyClassName);
    config.setBlockWhenExhausted(builder.blockWhenExhausted);
    config.setJmxEnabled(builder.jmxEnabled);
    config.setJmxNameBase(builder.jmxNameBase);
    config.setJmxNamePrefix(builder.jmxNamePrefix);
    return config;
}
 
開發者ID:vy,項目名稱:log4j2-redis-appender,代碼行數:24,代碼來源:RedisConnectionPoolConfig.java

示例4: getJedisCluster

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
@Bean
public JedisCluster getJedisCluster() {
    List<String> serverArray = redisProperties.getNodes();
    Set<HostAndPort> nodes = new HashSet<>();

    for (String ipPort : serverArray) {
        String[] ipPortPair = ipPort.split(":");
        nodes.add(new HostAndPort(ipPortPair[0].trim(), Integer.valueOf(ipPortPair[1].trim())));
    }
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(500);
    config.setMaxIdle(1000 * 60);
    config.setMaxWaitMillis(1000 * 10);
    config.setTestOnBorrow(true);
    return new JedisCluster(nodes, config);
}
 
開發者ID:Evan1120,項目名稱:springboot-sample,代碼行數:17,代碼來源:JedisClusterConfig.java

示例5: getRedisCluster

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
@Bean
public JedisCluster getRedisCluster(){
    Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes1"), Integer.parseInt(environment.getProperty("redis.cluster.port1"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes2"), Integer.parseInt(environment.getProperty("redis.cluster.port2"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes3"), Integer.parseInt(environment.getProperty("redis.cluster.port3"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes4"), Integer.parseInt(environment.getProperty("redis.cluster.port4"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes5"), Integer.parseInt(environment.getProperty("redis.cluster.port5"))));
    jedisClusterNode.add(new HostAndPort(environment.getProperty("redis.cluster.nodes6"), Integer.parseInt(environment.getProperty("redis.cluster.port6"))));
    JedisPoolConfig cfg = new JedisPoolConfig();
    cfg.setMaxTotal(Integer.parseInt(environment.getProperty("redis.cluster.config.max-total")));
    cfg.setMaxIdle(Integer.parseInt(environment.getProperty("redis.cluster.config.max-idle")));
    cfg.setMaxWaitMillis(Integer.parseInt(environment.getProperty("redis.cluster.config.max-waitmillis")));
    cfg.setTestOnBorrow(Boolean.parseBoolean(environment.getProperty("redis.cluster.config.onborrow"))); 
    JedisCluster jc = new JedisCluster(jedisClusterNode, Integer.parseInt(environment.getProperty("redis.cluster.timeout")), Integer.parseInt(environment.getProperty("redis.cluster.max-redirections")), cfg);
    return jc;
}
 
開發者ID:craware,項目名稱:webapp-tyust,代碼行數:18,代碼來源:ClusterConfig.java

示例6: connectionFactory

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
@Bean
public JedisConnectionFactory connectionFactory() {
  JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
  jedisPoolConfig.setMaxTotal(Integer.parseInt(env.getProperty(REDIS_POOL_MAX_ACTIVE)));
  jedisPoolConfig.setMaxIdle(Integer.parseInt(env.getProperty(REDIS_POOL_MAX_IDLE)));
  jedisPoolConfig.setMinIdle(Integer.parseInt(env.getProperty(REDIS_POOL_MIN_IDLE)));
  jedisPoolConfig.setMaxWaitMillis(Long.parseLong(env.getProperty(REDIS_POOL_MAX_WAIT)));
  jedisPoolConfig.setTestOnBorrow(true);
  jedisPoolConfig.setTestOnReturn(true);
  jedisPoolConfig.setTestWhileIdle(true);

  JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(jedisPoolConfig);
  jedisConnectionFactory.setUsePool(true);
  jedisConnectionFactory.setHostName(env.getProperty((REDIS_REMOTE_HOST)));
  return jedisConnectionFactory;
}
 
開發者ID:chuangxian,項目名稱:lib-edge,代碼行數:17,代碼來源:RedisSessionConfiguration.java

示例7: getPoolConfig

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
/**
 * 獲取poolconfig
 *
 * @return
 */
public JedisPoolConfig getPoolConfig() {
    JedisPoolConfig config = new JedisPoolConfig();
    if (getMaxIdle() != 0) {
        config.setMaxIdle(getMaxIdle());
    }
    if (getMinIdle() != 0) {
        config.setMinIdle(getMinIdle());
    }
    if (getMaxWaitMillis() != 0) {
        config.setMaxWaitMillis(getMaxWaitMillis());
    }
    if (getMaxTotal() != 0) {
        config.setMaxTotal(getMaxTotal());
    }
    config.setTestOnBorrow(true);
    config.setTestWhileIdle(true);
    return config;
}
 
開發者ID:AsuraTeam,項目名稱:asura,代碼行數:24,代碼來源:AbstractRedisCacheClient.java

示例8: redisConnectionFactory

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
@Bean
public JedisConnectionFactory redisConnectionFactory() {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(5);
    poolConfig.setTestOnBorrow(true);
    poolConfig.setTestOnReturn(true);
    JedisConnectionFactory ob = new JedisConnectionFactory(poolConfig);
    ob.setUsePool(true);
    String redishost = cacheProperties.getRedisHost(); //System.getenv("REDISCACHE_HOSTNAME");
    LOG.info("REDISCACHE_HOSTNAME={}", redishost);
    ob.setHostName(redishost);
    String redisport = cacheProperties.getRedisPort().toString(); //System.getenv("REDISCACHE_PORT");
    LOG.info("REDISCACHE_PORT= {}", redisport);
    try {
        ob.setPort(Integer.parseInt(  redisport));
    } catch (NumberFormatException e1) {
        // if the port is not in the ENV, use the default
        ob.setPort(6379);
    }
    String rediskey = cacheProperties.getPrimaryKey(); //System.getenv("REDISCACHE_PRIMARY_KEY");
    LOG.info("REDISCACHE_PRIMARY_KEY= {}", rediskey);
    ob.setPassword(rediskey);
    ob.afterPropertiesSet();
    RedisTemplate<Object,Object> tmp = new RedisTemplate<>();
    tmp.setConnectionFactory(ob);

    //make sure redis connection is working
    try {
        String msg = tmp.getConnectionFactory().getConnection().ping();
        LOG.info("redis ping response="+msg);
        //clear the cache before use
        tmp.getConnectionFactory().getConnection().flushAll();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return ob;
}
 
開發者ID:Azure,項目名稱:CityPower-Build-Sample,代碼行數:39,代碼來源:CacheConfig.java

示例9: getInstance

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
public static JedisConnector_Cache getInstance(){
	if (instance == null){
		instance = new JedisConnector_Cache();
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(Configs.getIntValue("x7.redis.max"));
		config.setMaxIdle(Configs.getIntValue("x7.redis.idle"));
		config.setJmxEnabled(true);
		config.setJmxNamePrefix("redis-cahce");
		config.setTestOnBorrow(true);
		
		pool = new JedisPool( config, Configs.getString("x7.redis.ip.cache"), Configs.getIntValue("x7.redis.port.cache"));  //6379
	}
	return instance;
}
 
開發者ID:x7-framework,項目名稱:x7,代碼行數:15,代碼來源:JedisConnector_Cache.java

示例10: createJedisConnectionFactory

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
private RedisConnectionFactory createJedisConnectionFactory(final LocalRedisProperties redisProperties) {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(redisProperties.getMinActive());
    poolConfig.setMinIdle(redisProperties.getMaxActive());
    poolConfig.setMaxWaitMillis(redisProperties.getMaxWaitTime());
    poolConfig.setTestOnBorrow(false);

    JedisConnectionFactory connFactory = new JedisConnectionFactory(poolConfig);
    connFactory.setUsePool(false);
    connFactory.setTimeout(redisProperties.getSoTimeout());
    connFactory.setHostName(redisProperties.getRedisHost());
    connFactory.setPort(redisProperties.getRedisPort());
    return connFactory;
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:15,代碼來源:LocalRedisConnectionFactoryConfig.java

示例11: defaultPoolConfig

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
public static JedisPoolConfig defaultPoolConfig() {
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(maxCount);
    config.setMaxIdle(maxIdle);
    config.setMaxWaitMillis(MaxWait);
    config.setTestOnBorrow(false);
    config.setTestOnReturn(false);
    return config;
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:10,代碼來源:PoolUtil.java

示例12: init

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
@Before
public void init() {
	String ip = "192.168.2.160";
	Set<HostAndPort> nodes = new HashSet<>();
	nodes.add(new HostAndPort(ip, 7701));
	nodes.add(new HostAndPort(ip, 7702));
	nodes.add(new HostAndPort(ip, 7703));
	nodes.add(new HostAndPort(ip, 7704));
	nodes.add(new HostAndPort(ip, 7705));
	nodes.add(new HostAndPort(ip, 7706));
	JedisPoolConfig pool = new JedisPoolConfig();
	pool.setMaxTotal(100);
	pool.setFairness(false);
	pool.setNumTestsPerEvictionRun(100);
	pool.setMaxWaitMillis(5000);
	pool.setTestOnBorrow(true);
	jedisCluster = new JedisCluster(nodes, 1000, 1000, 100, null, pool); // maxAttempt必須調大
	jedisCluster.set("test", "test");
	queue = new RedisDelayQueue("com.meipian", "delayqueue", jedisCluster, 60 * 1000,
			new DelayQueueProcessListener() {
				@Override
				public void pushCallback(Message message) {

				}

				@Override
				public void peekCallback(Message message) {
					System.out.println("message----->" + message);
					queue.ack(message.getId());//確認操作。將會刪除消息
				}

				@Override
				public void ackCallback(Message message) {
				}
			});

}
 
開發者ID:MeiPian,項目名稱:delay-queue,代碼行數:38,代碼來源:TestRedisDelayQueue.java

示例13: GedisCacheFactory

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
/**
 * 基於配置構造 GedisCacheFactory
 *
 * @param configPrefix   Redis 配置信息前綴
 * @param writeInitParam 寫實例初始化配置信息
 * @param readInitParams 讀實例初始化配置信息
 */
public GedisCacheFactory(String configPrefix, GedisInitParam writeInitParam, List<GedisInitParam> readInitParams) {
    if (writeInitParam == null && readInitParams == null && readInitParams.size() > 0) {
        throw new IllegalArgumentException("WriteInitParam and ReadInitParams can not both be null.");
    }
    this.configPrefix = configPrefix;
    try {
        if (writeInitParam != null) {
            JedisPoolConfig writeConfig = new JedisPoolConfig();
            writeConfig.setMaxTotal(writeInitParam.getMaxTotal());
            writeConfig.setMinIdle(writeInitParam.getMinIdle());
            writeConfig.setMaxIdle(writeInitParam.getMaxIdle());
            writeConfig.setMaxWaitMillis(writeInitParam.getMaxWaitInMillis());
            writeConfig.setTestOnBorrow(writeInitParam.isTestOnBorrow());
            writeInstance = new JedisPool(writeConfig, writeInitParam.getIp(), writeInitParam.getPort(), writeInitParam.getConnectTimeoutInMillis(), writeInitParam.getPassword());
        }
        if (readInitParams != null && readInitParams.size() > 0) {
            for (GedisInitParam param : readInitParams) {
                JedisPoolConfig readConfig = new JedisPoolConfig();
                readConfig.setMaxTotal(param.getMaxTotal());
                readConfig.setMinIdle(param.getMinIdle());
                readConfig.setMaxIdle(param.getMaxIdle());
                readConfig.setMaxWaitMillis(param.getMaxWaitInMillis());
                readConfig.setTestOnBorrow(param.isTestOnBorrow());
                JedisPool readInstance = new JedisPool(readConfig, param.getIp(), param.getPort(), param.getConnectTimeoutInMillis(), param.getPassword());
                this.readInstances.add(readInstance);
            }
        }
    } catch (Exception e) {
        log.error("GedisCacheFactory init failed, please check init params, error {}", e);
        throw e;
    }
    jedisInterface = new IJedisImpl(writeInstance, readInstances);
    methodInterceptor = new JedisMethodInterceptor(writeInstance, readInstances);
}
 
開發者ID:ganpengyu,項目名稱:gedis,代碼行數:42,代碼來源:GedisCacheFactory.java

示例14: afterPropertiesSet

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
/**
 * 初始化redisUtil實例,配置連接池
 */
public void afterPropertiesSet() throws Exception {

    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(maxTotal);
    config.setMaxIdle(maxIdle);
    config.setMinIdle(minIdle);
    config.setMaxWaitMillis(holed);
    config.setTestOnBorrow(false);

    pool = new JedisPool(config, host, port, timeout, password, DB);

}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:16,代碼來源:RedisUtil.java

示例15: main

import redis.clients.jedis.JedisPoolConfig; //導入方法依賴的package包/類
public static void main(String[] args) {
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(50000);
    jedisPoolConfig.setMaxIdle(20000);
    jedisPoolConfig.setMaxWaitMillis(3000);
    jedisPoolConfig.setTestOnBorrow(true);
    jedisPoolConfig.setTestOnReturn(true);

    List<JedisShardInfo> shards = new ArrayList<>();
    shards.add(new JedisShardInfo("127.0.0.1", 6379, 300));
    ShardedJedisPool shardedJedisPool = new ShardedJedisPool(jedisPoolConfig, shards);
    RedisService redisService = new RedisService(shardedJedisPool);
    new Thread(new HallTcpService(redisService)).start();
    new Thread(new HallNoticeService(redisService)).start();
}
 
開發者ID:peng9627,項目名稱:hall,代碼行數:16,代碼來源:StartGame.java


注:本文中的redis.clients.jedis.JedisPoolConfig.setTestOnBorrow方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。