Search in sources :

Example 96 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method testResetStateWhenInMulti.

@Test
public void testResetStateWhenInMulti() {
    jedis.auth("foobared");
    Transaction t = jedis.multi();
    t.set("foooo", "barrr");
    jedis.resetState();
    assertEquals(null, jedis.get("foooo"));
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 97 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method transactionResponseWithError.

@Test
public void transactionResponseWithError() {
    Transaction t = jedis.multi();
    t.set("foo", "bar");
    Response<Set<String>> error = t.smembers("foo");
    Response<String> r = t.get("foo");
    List<Object> l = t.exec();
    assertEquals(JedisDataException.class, l.get(1).getClass());
    try {
        error.get();
        fail("We expect exception here!");
    } catch (JedisDataException e) {
    // that is fine we should be here
    }
    assertEquals(r.get(), "bar");
}
Also used : Set(java.util.Set) Transaction(redis.clients.jedis.Transaction) JedisDataException(redis.clients.jedis.exceptions.JedisDataException) Test(org.junit.Test)

Example 98 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method testResetStateWhenInWatch.

@Test
public void testResetStateWhenInWatch() {
    jedis.watch("mykey", "somekey");
    // state reset : unwatch
    jedis.resetState();
    Transaction t = jedis.multi();
    nj.connect();
    nj.auth("foobared");
    nj.set("mykey", "bar");
    nj.disconnect();
    t.set("mykey", "foo");
    List<Object> resp = t.exec();
    assertNotNull(resp);
    assertEquals(1, resp.size());
    assertEquals("foo", jedis.get("mykey"));
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 99 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method watch.

@Test
public void watch() throws UnknownHostException, IOException {
    jedis.watch("mykey", "somekey");
    Transaction t = jedis.multi();
    nj.connect();
    nj.auth("foobared");
    nj.set("mykey", "bar");
    nj.disconnect();
    t.set("mykey", "foo");
    List<Object> resp = t.exec();
    assertEquals(null, resp);
    assertEquals("bar", jedis.get("mykey"));
    // Binary
    jedis.watch(bmykey, "foobar".getBytes());
    t = jedis.multi();
    nj.connect();
    nj.auth("foobared");
    nj.set(bmykey, bbar);
    nj.disconnect();
    t.set(bmykey, bfoo);
    resp = t.exec();
    assertEquals(null, resp);
    assertTrue(Arrays.equals(bbar, jedis.get(bmykey)));
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 100 with Transaction

use of redis.clients.jedis.Transaction in project cachecloud by sohutv.

the class TransactionCommandsTest method transactionResponse.

@Test
public void transactionResponse() {
    jedis.set("string", "foo");
    jedis.lpush("list", "foo");
    jedis.hset("hash", "foo", "bar");
    jedis.zadd("zset", 1, "foo");
    jedis.sadd("set", "foo");
    Transaction t = jedis.multi();
    Response<String> string = t.get("string");
    Response<String> list = t.lpop("list");
    Response<String> hash = t.hget("hash", "foo");
    Response<Set<String>> zset = t.zrange("zset", 0, -1);
    Response<String> set = t.spop("set");
    t.exec();
    assertEquals("foo", string.get());
    assertEquals("foo", list.get());
    assertEquals("bar", hash.get());
    assertEquals("foo", zset.get().iterator().next());
    assertEquals("foo", set.get());
}
Also used : Set(java.util.Set) Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Aggregations

Transaction (redis.clients.jedis.Transaction)149 Test (org.junit.Test)90 Jedis (redis.clients.jedis.Jedis)57 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)15 Set (java.util.Set)14 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)8 List (java.util.List)8 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)7 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)6 Protocol (redis.clients.jedis.Protocol)4 Response (redis.clients.jedis.Response)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 Header (redis.clients.jedis.graph.Header)4 Record (redis.clients.jedis.graph.Record)4 ResultSet (redis.clients.jedis.graph.ResultSet)4 Node (redis.clients.jedis.graph.entities.Node)4 Property (redis.clients.jedis.graph.entities.Property)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3