Search in sources :

Example 66 with Transaction

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

the class TransactionCommandsTest method testResetStateWithFullyExecutedTransaction.

@Test
public void testResetStateWithFullyExecutedTransaction() {
    Jedis jedis2 = createJedis();
    jedis2.auth("foobared");
    Transaction t = jedis2.multi();
    t.set("mykey", "foo");
    t.get("mykey");
    List<Object> resp = t.exec();
    assertNotNull(resp);
    assertEquals(2, resp.size());
    jedis2.resetState();
    jedis2.close();
}
Also used : Jedis(redis.clients.jedis.Jedis) Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 67 with Transaction

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

the class TransactionCommandsTest method multi.

@Test
public void multi() {
    Transaction trans = jedis.multi();
    trans.sadd("foo", "a");
    trans.sadd("foo", "b");
    trans.scard("foo");
    List<Object> response = trans.exec();
    List<Object> expected = new ArrayList<Object>();
    expected.add(1L);
    expected.add(1L);
    expected.add(2L);
    assertEquals(expected, response);
    // Binary
    trans = jedis.multi();
    trans.sadd(bfoo, ba);
    trans.sadd(bfoo, bb);
    trans.scard(bfoo);
    response = trans.exec();
    expected = new ArrayList<Object>();
    expected.add(1L);
    expected.add(1L);
    expected.add(2L);
    assertEquals(expected, response);
}
Also used : Transaction(redis.clients.jedis.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 68 with Transaction

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

the class TransactionCommandsTest method execFail.

@Test
public void execFail() {
    Transaction trans = jedis.multi();
    trans.set("a", "a");
    trans.set("b", "b");
    try (MockedStatic<Protocol> protocol = Mockito.mockStatic(Protocol.class)) {
        protocol.when(() -> Protocol.read(any())).thenThrow(JedisConnectionException.class);
        trans.exec();
        fail("Should get mocked JedisConnectionException.");
    } catch (JedisConnectionException jce) {
    // should be here
    } finally {
        // close() should pass
        trans.close();
    }
    assertTrue(jedis.isBroken());
}
Also used : Transaction(redis.clients.jedis.Transaction) Protocol(redis.clients.jedis.Protocol) JedisConnectionException(redis.clients.jedis.exceptions.JedisConnectionException) Test(org.junit.Test)

Example 69 with Transaction

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

the class TransactionCommandsTest method testResetStateWhenInWatch.

// 
// @Test
// public void testResetStateWhenInMultiWithinPipeline() {
// Pipeline p = jedis.pipelined();
// p.multi();
// p.set("foooo", "barrr");
// 
// jedis.resetState();
// assertNull(jedis.get("foooo"));
// }
@Test
public void testResetStateWhenInWatch() {
    jedis.watch("mykey", "somekey");
    // state reset : unwatch
    jedis.resetState();
    Transaction t = jedis.multi();
    nj.set("mykey", "bar");
    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 70 with Transaction

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

the class TransactionCommandsTest method transactionResponseWithinPipeline.

@Test(expected = IllegalStateException.class)
public void transactionResponseWithinPipeline() {
    jedis.set("string", "foo");
    Transaction t = jedis.multi();
    Response<String> string = t.get("string");
    string.get();
    t.exec();
}
Also used : 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