Package redis.clients.jedis

Examples of redis.clients.jedis.JedisPool$JedisFactory


  assertTrue(pool.isClosed());
    }

    @Test
    public void nonDefaultDatabase() {
  JedisPool pool0 = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
    hnp.getPort(), 2000, "foobared");
  Jedis jedis0 = pool0.getResource();
  jedis0.set("foo", "bar");
  assertEquals("bar", jedis0.get("foo"));
  pool0.returnResource(jedis0);
  pool0.destroy();
  assertTrue(pool0.isClosed());

  JedisPool pool1 = new JedisPool(new JedisPoolConfig(), hnp.getHost(),
    hnp.getPort(), 2000, "foobared", 1);
  Jedis jedis1 = pool1.getResource();
  assertNull(jedis1.get("foo"));
  pool1.returnResource(jedis1);
  pool1.destroy();
  assertTrue(pool1.isClosed());
    }
View Full Code Here


    public void startWithUrlString() {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  JedisPool pool = new JedisPool("redis://:foobared@localhost:6380/2");
  Jedis jedis = pool.getResource();
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
    }
View Full Code Here

    public void startWithUrl() throws URISyntaxException {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  JedisPool pool = new JedisPool(new URI(
    "redis://:foobared@localhost:6380/2"));
  Jedis jedis = pool.getResource();
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
    }
View Full Code Here

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

    @Test
    public void allowUrlWithNoDBAndNoPassword() throws URISyntaxException {
  new JedisPool("redis://localhost:6380");
  new JedisPool(new URI("redis://localhost:6380"));
    }
View Full Code Here

  new JedisPool(new URI("redis://localhost:6380"));
    }

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

  Jedis jedis0 = pool.getResource();
  assertEquals(0L, jedis0.getDB().longValue());

  jedis0.select(1);
  assertEquals(1L, jedis0.getDB().longValue());

  pool.returnResource(jedis0);

  Jedis jedis1 = pool.getResource();
  assertTrue("Jedis instance was not reused", jedis1 == jedis0);
  assertEquals(0L, jedis1.getDB().longValue());

  pool.returnResource(jedis1);
  pool.destroy();
  assertTrue(pool.isClosed());
    }
View Full Code Here

  assertTrue(pool.isClosed());
    }

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

  Jedis jedis = pool0.getResource();

  assertEquals("my_shiny_client_name", jedis.clientGetname());

  pool0.returnResource(jedis);
  pool0.destroy();
  assertTrue(pool0.isClosed());
    }
View Full Code Here

    @Test
    public void returnResourceShouldResetState() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
    2000, "foobared");

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

  Jedis jedis2 = pool.getResource();
  try {
      assertTrue(jedis == jedis2);
      assertEquals("jedis", jedis2.get("hello"));
  } finally {
      jedis2.close();
  }

  pool.destroy();
  assertTrue(pool.isClosed());
    }
View Full Code Here

    @Test
    public void checkResourceIsCloseable() {
  GenericObjectPoolConfig config = new GenericObjectPoolConfig();
  config.setMaxTotal(1);
  config.setBlockWhenExhausted(false);
  JedisPool pool = new JedisPool(config, hnp.getHost(), hnp.getPort(),
    2000, "foobared");

  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

  }
    }

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

  pool.returnBrokenResource(null);
  pool.returnResource(null);
  pool.returnResourceObject(null);
    }
View Full Code Here

  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

TOP

Related Classes of redis.clients.jedis.JedisPool$JedisFactory

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.