Package redis.clients.jedis

Examples of redis.clients.jedis.Jedis


  }
    }

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

  try {
      Map<String, String> parameterMap = new HashMap<String, String>();
      parameterMap.put("down-after-milliseconds", String.valueOf(1234));
      parameterMap.put("parallel-syncs", String.valueOf(3));
      parameterMap.put("quorum", String.valueOf(2));
      j.sentinelSet(MASTER_NAME, parameterMap);

      List<Map<String, String>> masters = j.sentinelMasters();
      for (Map<String, String> master : masters) {
    if (master.get("name").equals(MASTER_NAME)) {
        assertEquals(1234, Integer.parseInt(master
          .get("down-after-milliseconds")));
        assertEquals(3,
          Integer.parseInt(master.get("parallel-syncs")));
        assertEquals(2, Integer.parseInt(master.get("quorum")));
    }
      }

      parameterMap.put("quorum", String.valueOf(1));
      j.sentinelSet(MASTER_NAME, parameterMap);
  } finally {
      j.close();
  }
    }
View Full Code Here


  }
    }

    private void ensureMonitored(HostAndPort sentinel, String masterName,
      String ip, int port, int quorum) {
  Jedis j = new Jedis(sentinel.getHost(), sentinel.getPort());
  try {
      j.sentinelMonitor(masterName, ip, port, quorum);
  } catch (JedisDataException e) {
  } finally {
      j.close();
  }
    }
View Full Code Here

    @Test
    public void checkConnections() {
  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"));
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
    }
View Full Code Here

    @Test
    public void checkCloseableConnections() throws Exception {
  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"));
  pool.returnResource(jedis);
  pool.close();
  assertTrue(pool.isClosed());
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
  super.setUp();

  nj = new Jedis(hnp.getHost(), hnp.getPort(), 500);
  nj.connect();
  nj.auth("foobared");
  nj.flushAll();
    }
View Full Code Here

  jedis.watch("foo");
  Transaction t = jedis.multi();
  t.select(0);
  t.set("bar", "foo");

  Jedis jedis2 = createJedis();
  jedis2.select(1);
  jedis2.set("foo", "bar2");

  List<Object> results = t.exec();

  assertNull(results);
    }
View Full Code Here

    @Test
    public void checkConnectionWithDefaultPort() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
    hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "bar");
  assertEquals("bar", jedis.get("foo"));
  pool.returnResource(jedis);
  pool.destroy();
  assertTrue(pool.isClosed());
    }
View Full Code Here

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

    @Test
    public void checkPoolRepairedWhenJedisIsBroken() {
  JedisPool pool = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
    hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.quit();
  pool.returnBrokenResource(jedis);

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

    public void checkPoolOverflow() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort());
  Jedis jedis = pool.getResource();
  jedis.auth("foobared");
  jedis.set("foo", "0");

  Jedis newJedis = pool.getResource();
  newJedis.auth("foobared");
  newJedis.incr("foo");
    }
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.