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


Java JedisPoolConfig類代碼示例

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


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

示例1: checkJedisIsReusedWhenReturned

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void checkJedisIsReusedWhenReturned() {

  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisPoolTest.java

示例2: jedisConnConfig

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
private void jedisConnConfig(final JedisConnectionFactory jedisConnectionFactory) {
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    try {
        poolConfig.setMaxTotal(Integer.parseInt(REDIS_MAXTOTAL.getValue()));
        poolConfig.setMaxIdle(Integer.parseInt(REDIS_MAXIDLE.getValue()));
        poolConfig.setBlockWhenExhausted(true);
        if (!"".equals(REDIS_PASSWORD.getValue())) {
            jedisConnectionFactory.setPassword(REDIS_PASSWORD.getValue());
        }
        if (!"".equals(REDIS_DATABASE.getValue())) {
            jedisConnectionFactory.setDatabase(Integer.parseInt(REDIS_DATABASE.getValue()));
        }
        jedisConnectionFactory.setPoolConfig(poolConfig);
        jedisConnectionFactory.setUsePool(true);
        jedisConnectionFactory.setTimeout(Integer.parseInt(REDIS_TIMEOUT.getValue()));
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
}
 
開發者ID:globocom,項目名稱:groot,代碼行數:20,代碼來源:RedisConfiguration.java

示例3: configure

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Override
protected void configure() {
	bind(HealthCheckHandler.class).toInstance(new HealthcheckResource());
	
	bind(RequrestAdapter.class).to(RxNettyServiceAdapter.class);
	
	bind(MeetupResource.class).asEagerSingleton();
	bind(MeetupService.class).to(MeetupServiceImpl.class);
	bind(MeetupDAO.class).to(MeetupDAOImpl.class);

	bind(JedisPool.class).toInstance(
			new JedisPool(
					new JedisPoolConfig(), 
					 ConfigurationManager.getConfigInstance().getString("redis_ip","localhost")));
	
}
 
開發者ID:diegopacheco,項目名稱:Building_Effective_Microservices,代碼行數:17,代碼來源:GuiceBindings.java

示例4: test_jedis_tracer

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void test_jedis_tracer() throws Exception {
    Brave.Builder builder = new Brave.Builder("jedis-interceptor-test");
    builder.spanCollector(HttpSpanCollector.create("http://192.168.150.132:9411", new EmptySpanCollectorMetricsHandler()));
    builder.traceSampler(Sampler.ALWAYS_SAMPLE);
    Brave brave = builder.build();
    JaRedisInterceptor.setClientTracer(brave.clientTracer());

    JedisPoolConfig config = new JedisPoolConfig();
    JaRedisPool proxyPool = new JaRedisPool(config, "127.0.0.1", 6379);
    Jedis jedis = proxyPool.getResource();
    jedis.set("hello", "world");
    Assert.assertEquals(jedis.get("hello"), "world");
    jedis.hgetAll("hello-map");
    jedis.close();
    // sleep 3s in case spanCollector not flushed
    Thread.sleep(3000);
}
 
開發者ID:YanXs,項目名稱:nighthawk,代碼行數:19,代碼來源:TestJedisProxyPool.java

示例5: 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

示例6: connect

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Override
public void connect(NURL nurl) {
	super.connect(nurl);
	this.retryPeriod = nurl.getParameter("retryPeriod", retryPeriod);

	JedisPoolConfig config = new JedisPoolConfig();
	Map<String, String> parameters = nurl.getParameters();
	if (parameters != null) {
		if (!parameters.isEmpty()) {
			try {
				Beans.copyProperties(config, nurl.getParameters());
			} catch (Exception e) {
				logger.error("The copy properties exception.", e);
			}
		}
	}

	jedisPool = new JedisPool(config, nurl.getHost(), nurl.getPort());
}
 
開發者ID:yu120,項目名稱:coon,代碼行數:20,代碼來源:RedisMconf.java

示例7: connect

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
private void connect()
{
    JedisPoolConfig config = new JedisPoolConfig();
    config.setMaxTotal(-1);
    config.setJmxEnabled(false);

    try
    {
        this.cachePool = new JedisPool(config, this.bungee.getIp(), this.bungee.getPort(), 0, this.bungee.getPassword());
        this.cachePool.getResource().close();

        this.plugin.log(Level.INFO, "Connected to database.");
    }
    catch (Exception e)
    {
        plugin.getLogger().log(Level.SEVERE, "Can't connect to the database!", e);
        Bukkit.shutdown();
    }
}
 
開發者ID:SamaGames,項目名稱:SamaGamesCore,代碼行數:20,代碼來源:DatabaseConnector.java

示例8: 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

示例9: redisConnectionFactory

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Bean
public RedisConnectionFactory redisConnectionFactory() {
    String default_host = "localhost";
    int port = 6379;
    String host = null;
    { // setup the host using the env vars
        host = System.getenv().get(SELDON_CLUSTER_MANAGER_REDIS_HOST_KEY);
        if (host == null) {
            logger.error(String.format("FAILED to find env var [%s]", SELDON_CLUSTER_MANAGER_REDIS_HOST_KEY));
            host = default_host;
        }
    }

    logger.info(String.format("setting up connection factory, host[%s] port[%d]", host, port));
    JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();
    jedisConnectionFactory.setHostName(host);
    jedisConnectionFactory.setPort(port);
    jedisConnectionFactory.setPassword("");
    jedisConnectionFactory.setUsePool(true);
    jedisConnectionFactory.setPoolConfig(new JedisPoolConfig());
    return jedisConnectionFactory;
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:23,代碼來源:RedisConfig.java

示例10: nonDefaultDatabase

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void nonDefaultDatabase() {
  JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared");
  Jedis jedis0 = pool0.getResource();
  jedis0.set("foo", "bar");
  assertEquals("bar", jedis0.get("foo"));
  pool0.returnResource(jedis0);
  pool0.destroy();
  assertTrue(pool0.isClosed());

  JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared", 1);
  Jedis jedis1 = pool1.getResource();
  assertNull(jedis1.get("foo"));
  pool1.returnResource(jedis1);
  pool1.destroy();
  assertTrue(pool1.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:JedisPoolTest.java

示例11: selectDatabaseOnActivation

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void selectDatabaseOnActivation() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "foobared");

  Jedis jedis0 = pool.getResource();
  assertEquals(0L, jedis0.getDB().longValue());

  jedis0.select(1);
  assertEquals(1L, jedis0.getDB().longValue());

  pool.returnResource(jedis0);

  Jedis jedis1 = pool.getResource();
  assertTrue("Jedis instance was not reused", jedis1 == jedis0);
  assertEquals(0L, jedis1.getDB().longValue());

  pool.returnResource(jedis1);
  pool.destroy();
  assertTrue(pool.isClosed());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:22,代碼來源:JedisPoolTest.java

示例12: getNumActiveReturnsTheCorrectNumber

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void getNumActiveReturnsTheCorrectNumber() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));

  assertEquals(1, pool.getNumActive());

  Jedis jedis2 = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");

  assertEquals(2, pool.getNumActive());

  pool.returnResource(jedis);
  assertEquals(1, pool.getNumActive());

  pool.returnResource(jedis2);

  assertEquals(0, pool.getNumActive());

  pool.destroy();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:26,代碼來源:JedisPoolTest.java

示例13: testAddObject

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void testAddObject() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000);
  pool.addObjects(1);
  assertEquals(pool.getNumIdle(), 1);
  pool.destroy();

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:9,代碼來源:JedisPoolTest.java

示例14: testCloseConnectionOnMakeObject

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
@Test
public void testCloseConnectionOnMakeObject() {
  JedisPoolConfig config = new JedisPoolConfig();
  config.setTestOnBorrow(true);
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(), hnp.getPort(), 2000,
      "wrong pass");
  Jedis jedis = new Jedis("redis://:[email protected]:6379/");
  int currentClientCount = getClientCount(jedis.clientList());
  try {
    pool.getResource();
    fail("Should throw exception as password is incorrect.");
  } catch (Exception e) {
    assertEquals(currentClientCount, getClientCount(jedis.clientList()));
  }

}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:JedisPoolTest.java

示例15: ApiService

import redis.clients.jedis.JedisPoolConfig; //導入依賴的package包/類
public ApiService(final Properties properties) throws URISyntaxException {
    this.properties = properties;
    this.requestLog = new RequestLogFactory(LOGGER).create();
    EmbeddedJettyFactory factory = new EmbeddedJettyFactoryConstructor(requestLog).create();
    EmbeddedServers.add(EmbeddedServers.Identifiers.JETTY, factory);
    final JedisPoolConfig poolConfig = new JedisPoolConfig();
    poolConfig.setMaxTotal(128); // maximum active connections
    poolConfig.setMaxIdle(32);  // maximum idle connections

    this.jedisPool = new JedisPool(poolConfig, new URI(properties.getProperty("caching.redis_host")));
    this.supersetCredential = new Credential(
            properties.getProperty("superset.user"),
            properties.getProperty("superset.password")
    );

    this.dafApiCredential = new Credential(
            properties.getProperty("daf_api.user"),
            properties.getProperty("daf_api.password")
    );

}
 
開發者ID:italia,項目名稱:daf-cacher,代碼行數:22,代碼來源:ApiService.java


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