当前位置: 首页>>代码示例>>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;未经允许,请勿转载。