Examples of JedisPool


Examples of redis.clients.jedis.JedisPool

  pool.returnResourceObject(null);
    }

    @Test
    public void getNumActiveIsNegativeWhenPoolIsClosed() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
    hnp.getPort(), 2000, "foobared", 0, "my_shiny_client_name");

  pool.destroy();
  assertTrue(pool.getNumActive() < 0);
    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

  assertTrue(pool.getNumActive() < 0);
    }

    @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();
    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

  long elapsed = System.currentTimeMillis() - t;
  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
    }

    private static void withPool() throws Exception {
  final JedisPool pool = new JedisPool(new GenericObjectPoolConfig(),
    hnp.getHost(), hnp.getPort(), 2000, "foobared");
  List<Thread> tds = new ArrayList<Thread>();

  final AtomicInteger ind = new AtomicInteger();
  for (int i = 0; i < 50; i++) {
      Thread hj = new Thread(new Runnable() {
    public void run() {
        for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) {
      try {
          Jedis j = pool.getResource();
          final String key = "foo" + i;
          j.set(key, key);
          j.get(key);
          pool.returnResource(j);
      } catch (Exception e) {
          e.printStackTrace();
      }
        }
    }
      });
      tds.add(hj);
      hj.start();
  }

  for (Thread t : tds)
      t.join();

  pool.destroy();

    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

        startJedisEngine();
    }

    protected void startJedisEngine() {
        if (benchmarkMode) {
            jedisPool = new JedisPool(new Config(), "localhost",
                    Protocol.DEFAULT_PORT, 2000);
        } else {
            jedisPool = new JedisPool(new Config(), "localhost");
        }
        JOhm.setPool(jedisPool);
        purgeRedis();
    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

          connectionPool = new JedisSentinelPool(getSentinelMaster(), sentinelSet, this.connectionPoolConfig, getTimeout(), getPassword());
        } else {
          throw new LifecycleException("Error configuring Redis Sentinel connection pool: expected both `sentinelMaster` and `sentiels` to be configured");
        }
      } else {
        connectionPool = new JedisPool(this.connectionPoolConfig, getHost(), getPort(), getTimeout(), getPassword());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new LifecycleException("Error connecting to Redis", e);
    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

  protected int redisTimeout = Protocol.DEFAULT_TIMEOUT;
  protected JedisPool redisConnectionPool;

  private void initializeJedisConnectionPool() {
    try {
      redisConnectionPool = new JedisPool(new JedisPoolConfig(), redisHost, redisPort, redisTimeout, redisPassword);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

        poolConfig.lifo = this.lifo;

        if (StringUtils.isEmpty(redisAuthKey)) {

            LOG.info("use no auth mode for " + redisServerHost);
            jedisPool = new JedisPool(poolConfig, redisServerHost,
                    redisServerPort, timeout);
        } else {
            jedisPool = new JedisPool(poolConfig, redisServerHost,
                    redisServerPort, timeout, redisAuthKey);
        }

        onAfterInit(redisServerHost, redisServerPort);
    }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

                port = Integer.parseInt(address.substring(i + 1));
            } else {
                host = address;
                port = DEFAULT_REDIS_PORT;
            }
            this.jedisPools.put(address, new JedisPool(config, host, port,
                    url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
        }
       
        this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
        String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
View Full Code Here

Examples of redis.clients.jedis.JedisPool

        }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
    }
   
    private void deferExpired() {
        for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
            JedisPool jedisPool = entry.getValue();
            try {
                Jedis jedis = jedisPool.getResource();
                try {
                    for (URL url : new HashSet<URL>(getRegistered())) {
                        if (url.getParameter(Constants.DYNAMIC_KEY, true)) {
                            String key = toCategoryPath(url);
                            if (jedis.hset(key, url.toFullString(), String.valueOf(System.currentTimeMillis() + expirePeriod)) == 1) {
                                jedis.publish(key, Constants.REGISTER);
                            }
                        }
                    }
                    if (admin) {
                        clean(jedis);
                    }
                } finally {
                    jedisPool.returnResource(jedis);
                }
            } catch (Throwable t) {
                logger.warn("Failed to write provider heartbeat to redis registry. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
            }
        }
View Full Code Here

Examples of redis.clients.jedis.JedisPool

            }
        } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
        }
        for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
            JedisPool jedisPool = entry.getValue();
            try {
                jedisPool.destroy();
            } catch (Throwable t) {
                logger.warn("Failed to destroy the redis registry client. registry: " + entry.getKey() + ", cause: " + t.getMessage(), t);
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.