Package redis.clients.jedis

Examples of redis.clients.jedis.Jedis


    @Test
    public void connectWithShardInfo() {
  JedisShardInfo shardInfo = new JedisShardInfo("localhost",
    Protocol.DEFAULT_PORT);
  shardInfo.setPassword("foobared");
  Jedis jedis = new Jedis(shardInfo);
  jedis.get("foo");
    }
View Full Code Here


  jedis.get("foo");
    }

    @Test(expected = JedisConnectionException.class)
    public void timeoutConnection() throws Exception {
  jedis = new Jedis("localhost", 6379, 15000);
  jedis.auth("foobared");
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
    }
View Full Code Here

  jedis.hmget("foobar", "foo");
    }

    @Test(expected = JedisConnectionException.class)
    public void timeoutConnectionWithURI() throws Exception {
  jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"), 15000);
  jedis.configSet("timeout", "1");
  Thread.sleep(2000);
  jedis.hmget("foobar", "foo");
    }
View Full Code Here

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

    @Test
    public void startWithUrlString() {
  Jedis j = new Jedis("localhost", 6380);
  j.auth("foobared");
  j.select(2);
  j.set("foo", "bar");
  Jedis jedis = new Jedis("redis://:foobared@localhost:6380/2");
  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.select(2);
  j.set("foo", "bar");
  Jedis jedis = new Jedis(new URI("redis://:foobared@localhost:6380/2"));
  assertEquals("PONG", jedis.ping());
  assertEquals("bar", jedis.get("foo"));
    }
View Full Code Here

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

    @Test
    public void allowUrlWithNoDBAndNoPassword() {
  Jedis jedis = new Jedis("redis://localhost:6380");
  jedis.auth("foobared");
  assertEquals(jedis.getClient().getHost(), "localhost");
  assertEquals(jedis.getClient().getPort(), 6380);
  assertEquals(jedis.getDB(), (Long) 0L);

  jedis = new Jedis("redis://localhost:6380/");
  jedis.auth("foobared");
  assertEquals(jedis.getClient().getHost(), "localhost");
  assertEquals(jedis.getClient().getPort(), 6380);
  assertEquals(jedis.getDB(), (Long) 0L);
    }
View Full Code Here

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

    public static void main(String[] args) throws Exception {
  Jedis j = new Jedis(hnp.getHost(), hnp.getPort());
  j.connect();
  j.auth("foobared");
  j.flushAll();
  j.quit();
  j.disconnect();
  long t = System.currentTimeMillis();
  // withoutPool();
  withPool();
  long elapsed = System.currentTimeMillis() - t;
  System.out.println(((1000 * 2 * TOTAL_OPERATIONS) / elapsed) + " ops");
View Full Code Here

  for (int i = 0; i < 50; i++) {
      Thread hj = new Thread(new Runnable() {
    public void run() {
        for (int i = 0; (i = ind.getAndIncrement()) < TOTAL_OPERATIONS;) {
      try {
          Jedis j = pool.getResource();
          final String key = "foo" + i;
          j.set(key, key);
          j.get(key);
          pool.returnResource(j);
      } catch (Exception e) {
          e.printStackTrace();
      }
        }
View Full Code Here

        JOhm.setPool(jedisPool);
        purgeRedis();
    }

    protected void purgeRedis() {
        Jedis jedis = jedisPool.getResource();
        jedis.flushAll();
        jedisPool.returnResource(jedis);
    }
View Full Code Here

        assertEquals("users", users.key());
        assertEquals("users:123", users.cat(123).key());
        assertEquals("users:123:name", users.cat(123).cat("name").key());

        users.cat(123).cat("name").set("foo");
        Jedis jedis = jedisPool.getResource();
        assertEquals("foo", jedis.get("users:123:name"));
        jedisPool.returnBrokenResource(jedis);
        assertEquals("foo", users.cat(123).cat("name").get());
    }
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.