Package redis.clients.jedis

Examples of redis.clients.jedis.Jedis


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


  assertEquals(fails, c2);
    }

    @Test
    public void startWithUrlString() {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.set("foo", "bar");

  j = new Jedis("localhost", 6379);
  j.auth("foobared");
  j.set("foo", "bar");

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo("redis://:foobared@localhost:6380"));
  shards.add(new JedisShardInfo("redis://:foobared@localhost:6379"));

  GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
  ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);

  Jedis[] jedises = pool.getResource().getAllShards()
    .toArray(new Jedis[2]);

  Jedis jedis = jedises[0];
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));

  jedis = jedises[1];
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
    }
View Full Code Here

  assertEquals("bar", jedis.get("foo"));
    }

    @Test
    public void startWithUrl() throws URISyntaxException {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.set("foo", "bar");

  j = new Jedis("localhost", 6379);
  j.auth("foobared");
  j.set("foo", "bar");

  List<JedisShardInfo> shards = new ArrayList<JedisShardInfo>();
  shards.add(new JedisShardInfo(new URI(
    "redis://:foobared@localhost:6380")));
  shards.add(new JedisShardInfo(new URI(
    "redis://:foobared@localhost:6379")));

  GenericObjectPoolConfig redisConfig = new GenericObjectPoolConfig();
  ShardedJedisPool pool = new ShardedJedisPool(redisConfig, shards);

  Jedis[] jedises = pool.getResource().getAllShards()
    .toArray(new Jedis[2]);

  Jedis jedis = jedises[0];
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));

  jedis = jedises[1];
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
    }
View Full Code Here

    private HostAndPort nodeInfo2 = HostAndPortUtil.getClusterServers().get(1);

    @Before
    public void setUp() throws Exception {

  node1 = new Jedis(nodeInfo1.getHost(), nodeInfo1.getPort());
  node1.connect();
  node1.flushAll();

  node2 = new Jedis(nodeInfo2.getHost(), nodeInfo2.getPort());
  node2.connect();
  node2.flushAll();
    }
View Full Code Here

  JedisShardInfo s1 = jedis.getShardInfo("a");
  jedis.set("b", "bar1");
  JedisShardInfo s2 = jedis.getShardInfo("b");
  jedis.disconnect();

  Jedis j = new Jedis(s1.getHost(), s1.getPort());
  j.auth("foobared");
  assertEquals("bar", j.get("a"));
  j.disconnect();

  j = new Jedis(s2.getHost(), s2.getPort());
  j.auth("foobared");
  assertEquals("bar1", j.get("b"));
  j.disconnect();
    }
View Full Code Here

  JedisShardInfo s1 = jedis.getShardInfo("a");
  jedis.set("b", "bar1");
  JedisShardInfo s2 = jedis.getShardInfo("b");
  jedis.disconnect();

  Jedis j = new Jedis(s1.getHost(), s1.getPort());
  j.auth("foobared");
  assertEquals("bar", j.get("a"));
  j.disconnect();

  j = new Jedis(s2.getHost(), s2.getPort());
  j.auth("foobared");
  assertEquals("bar1", j.get("b"));
  j.disconnect();
    }
View Full Code Here

  ensureRemoved(REMOVE_MASTER_NAME);
    }

    @Test
    public void sentinel() {
  Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());

  try {
      List<Map<String, String>> masters = j.sentinelMasters();

      boolean inMasters = false;
      for (Map<String, String> master : masters)
    if (MASTER_NAME.equals(master.get("name")))
        inMasters = true;

      assertTrue(inMasters);

      List<String> masterHostAndPort = j
        .sentinelGetMasterAddrByName(MASTER_NAME);
      HostAndPort masterFromSentinel = new HostAndPort(
        masterHostAndPort.get(0),
        Integer.parseInt(masterHostAndPort.get(1)));
      assertEquals(master, masterFromSentinel);

      List<Map<String, String>> slaves = j.sentinelSlaves(MASTER_NAME);
      assertTrue(slaves.size() > 0);
      assertEquals(master.getPort(),
        Integer.parseInt(slaves.get(0).get("master-port")));

      // DO NOT RE-RUN TEST TOO FAST, RESET TAKES SOME TIME TO... RESET
      assertEquals(Long.valueOf(1), j.sentinelReset(MASTER_NAME));
      assertEquals(Long.valueOf(0), j.sentinelReset("woof" + MASTER_NAME));
  } finally {
      j.close();
  }
    }
View Full Code Here

  }
    }

    @Test
    public void sentinelFailover() throws InterruptedException {
  Jedis j = new Jedis(sentinelForFailover.getHost(),
    sentinelForFailover.getPort());
  Jedis j2 = new Jedis(sentinelForFailover.getHost(),
    sentinelForFailover.getPort());

  try {
      List<String> masterHostAndPort = j
        .sentinelGetMasterAddrByName(FAILOVER_MASTER_NAME);
View Full Code Here

    }

    @Test
    public void sentinelMonitor() {
  Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());

  try {
      // monitor new master
      String result = j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP,
        master.getPort(), 1);
      assertEquals("OK", result);

      // already monitored
      try {
    j.sentinelMonitor(MONITOR_MASTER_NAME, MASTER_IP,
      master.getPort(), 1);
    fail();
      } catch (JedisDataException e) {
    // pass
      }
  } finally {
      j.close();
  }
    }
View Full Code Here

  }
    }

    @Test
    public void sentinelRemove() {
  Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());

  try {
      ensureMonitored(sentinel, REMOVE_MASTER_NAME, MASTER_IP,
        master.getPort(), 1);

      String result = j.sentinelRemove(REMOVE_MASTER_NAME);
      assertEquals("OK", result);

      // not exist
      try {
    result = j.sentinelRemove(REMOVE_MASTER_NAME);
    assertNotEquals("OK", result);
    fail();
      } catch (JedisDataException e) {
    // pass
      }
  } finally {
      j.close();
  }
    }
View Full Code Here

TOP

Related Classes of redis.clients.jedis.Jedis

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.