Package redis.clients.jedis

Examples of redis.clients.jedis.ShardedJedis


  shardInfo1.setPassword("foobared");
  shardInfo2.setPassword("foobared");
  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(shardInfo1);
  shards.add(shardInfo2);
  this.jedis = new ShardedJedis(shards);

    }
View Full Code Here


    @Test
    public void checkConnections() {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void checkCloseableConnections() throws Exception {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
    }
View Full Code Here

    @Test
    public void checkConnectionWithDefaultPort() {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void checkJedisIsReusedWhenReturned() {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");
  pool.returnResource(jedis);

  jedis = pool.getResource();
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void checkPoolRepairedWhenJedisIsBroken() {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.disconnect();
  pool.returnBrokenResource(jedis);

  jedis = pool.getResource();
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
    }
View Full Code Here

  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis jedis = pool.getResource();
  jedis.set("foo", "0");

  ShardedJedis newJedis = pool.getResource();
  newJedis.incr("foo");
    }
View Full Code Here

  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(2);

  ShardedJedisPool pool = new ShardedJedisPool(config, shards);

  ShardedJedis j1 = pool.getResource();
  ShardedJedis j2 = pool.getResource();

  assertNotSame(j1.getShard("foo"), j2.getShard("foo"));
    }
View Full Code Here

    @Test
    public void checkFailedJedisServer() {
  ShardedJedisPool pool = new ShardedJedisPool(
    new GenericObjectPoolConfig(), shards);
  ShardedJedis jedis = pool.getResource();
  jedis.incr("foo");
  pool.returnResource(jedis);
  pool.destroy();
    }
View Full Code Here

    @Test
    public void shouldReturnActiveShardsWhenOneGoesOffline() {
  GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
  redisConfig.setTestOnBorrow(false);
  ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);
  ShardedJedis jedis = pool.getResource();
  // fill the shards
  for (int i = 0; i < 1000; i++) {
      jedis.set("a-test-" + i, "0");
  }
  pool.returnResource(jedis);
  // check quantity for each shard
  Jedis j = new Jedis(shards.get(0));
  j.connect();
  Long c1 = j.dbSize();
  j.disconnect();
  j = new Jedis(shards.get(1));
  j.connect();
  Long c2 = j.dbSize();
  j.disconnect();
  // shutdown shard 2 and check thay the pool returns an instance with c1
  // items on one shard
  // alter shard 1 and recreate pool
  pool.destroy();
  shards.set(1, new JedisShardInfo("localhost", 1234));
  pool = new ShardedJedisPool(redisConfig, shards);
  jedis = pool.getResource();
  Long actual = Long.valueOf(0);
  Long fails = Long.valueOf(0);
  for (int i = 0; i < 1000; i++) {
      try {
    jedis.get("a-test-" + i);
    actual++;
      } catch (RuntimeException e) {
    fails++;
      }
  }
View Full Code Here

TOP

Related Classes of redis.clients.jedis.ShardedJedis

Copyright © 2018 www.massapicom. 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.