Package redis.clients.jedis

Examples of redis.clients.jedis.Jedis


    public void checkCloseableConnections() throws Exception {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();

  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);
  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


  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis jedis = pool.getResource();
  Jedis jedis2 = null;

  try {
      jedis.set("hello", "jedis");
      Transaction t = jedis.multi();
      t.set("hello", "world");
      pool.returnResource(jedis);

      jedis2 = pool.getResource();

      assertTrue(jedis == jedis2);
      assertEquals("jedis", jedis2.get("hello"));
  } catch (JedisConnectionException e) {
      if (jedis2 != null) {
    pool.returnBrokenResource(jedis2);
    jedis2 = null;
      }
View Full Code Here

  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis jedis = pool.getResource();
  try {
      jedis.set("hello", "jedis");
  } finally {
      jedis.close();
  }

  Jedis jedis2 = pool.getResource();
  try {
      assertEquals(jedis, jedis2);
  } finally {
      jedis2.close();
  }
    }
View Full Code Here

  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis nullJedis = null;
  pool.returnResource(nullJedis);
  pool.destroy();
    }
View Full Code Here

  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisSentinelPool pool = new JedisSentinelPool(MASTER_NAME, sentinels,
    config, 1000, "foobared", 2);

  Jedis nullJedis = null;
  pool.returnBrokenResource(nullJedis);
  pool.destroy();
    }
View Full Code Here

    private void forceFailover(JedisSentinelPool pool)
      throws InterruptedException {
  HostAndPort oldMaster = pool.getCurrentHostMaster();

  // jedis connection should be master
  Jedis beforeFailoverJedis = pool.getResource();
  assertEquals("PONG", beforeFailoverJedis.ping());

  waitForFailover(pool, oldMaster);

  Jedis afterFailoverJedis = pool.getResource();
  assertEquals("PONG", afterFailoverJedis.ping());
  assertEquals("foobared", afterFailoverJedis.configGet("requirepass")
    .get(1));
  assertEquals(2, afterFailoverJedis.getDB().intValue());

  // returning both connections to the pool should not throw
  beforeFailoverJedis.close();
  afterFailoverJedis.close();
    }
View Full Code Here

    private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
    private static final int TOTAL_OPERATIONS = 200000;

    public static void main(String[] args) throws UnknownHostException,
      IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  Pipeline p = jedis.pipelined();
  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
      String key = "foo" + n;
      p.set(key, "bar" + n);
      p.get(key);
  }
  p.sync();

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
    }
View Full Code Here

    private static HostAndPort hnp = HostAndPortUtil.getRedisServers().get(0);
    private static final int TOTAL_OPERATIONS = 100000;

    public static void main(String[] args) throws UnknownHostException,
      IOException {
  Jedis jedis = new Jedis(hnp.getHost(), hnp.getPort());
  jedis.connect();
  jedis.auth("foobared");
  jedis.flushAll();

  long begin = Calendar.getInstance().getTimeInMillis();

  for (int n = 0; n <= TOTAL_OPERATIONS; n++) {
      String key = "foo" + n;
      jedis.set(key, "bar" + n);
      jedis.get(key);
  }

  long elapsed = Calendar.getInstance().getTimeInMillis() - begin;

  jedis.disconnect();

  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
    }
View Full Code Here

import redis.clients.util.SafeEncoder;

public class JedisTest extends JedisCommandTestBase {
    @Test
    public void useWithoutConnecting() {
  Jedis jedis = new Jedis("localhost");
  jedis.auth("foobared");
  jedis.dbSize();
    }
View Full Code Here

    public void brpoplpush() {
  (new Thread(new Runnable() {
      public void run() {
    try {
        Thread.sleep(100);
        Jedis j = createJedis();
        j.lpush("foo", "a");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
      }
  })).start();

  String element = jedis.brpoplpush("foo", "bar", 0);

  assertEquals("a", element);
  assertEquals(1, jedis.llen("bar").longValue());
  assertEquals("a", jedis.lrange("bar", 0, -1).get(0));

  (new Thread(new Runnable() {
      public void run() {
    try {
        Thread.sleep(100);
        Jedis j = createJedis();
        j.lpush("foo", "a");
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
      }
  })).start();
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.