Search in sources :

Example 1 with Transaction

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

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 2 with Transaction

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

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)

Example 3 with Transaction

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

the class TransactionCommandsTest method transactionResponseWithinPipeline.

@Test(expected = JedisDataException.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)

Example 4 with Transaction

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

the class TransactionCommandsTest method unwatch.

@Test
public void unwatch() throws UnknownHostException, IOException {
    jedis.watch("mykey");
    String val = jedis.get("mykey");
    val = "foo";
    String status = jedis.unwatch();
    assertEquals("OK", status);
    Transaction t = jedis.multi();
    nj.connect();
    nj.auth("foobared");
    nj.set("mykey", "bar");
    nj.disconnect();
    t.set("mykey", val);
    List<Object> resp = t.exec();
    assertEquals(1, resp.size());
    assertEquals("OK", resp.get(0));
    // Binary
    jedis.watch(bmykey);
    byte[] bval = jedis.get(bmykey);
    bval = bfoo;
    status = jedis.unwatch();
    assertEquals(Keyword.OK.name(), status);
    t = jedis.multi();
    nj.connect();
    nj.auth("foobared");
    nj.set(bmykey, bbar);
    nj.disconnect();
    t.set(bmykey, bval);
    resp = t.exec();
    assertEquals(1, resp.size());
    assertEquals("OK", resp.get(0));
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 5 with Transaction

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

the class TransactionCommandsTest method testResetStateWithFullyExecutedTransaction.

@Test
public void testResetStateWithFullyExecutedTransaction() {
    Jedis jedis2 = new Jedis(jedis.getClient().getHost(), jedis.getClient().getPort());
    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)

Aggregations

Transaction (redis.clients.jedis.Transaction)85 Test (org.junit.Test)66 Jedis (redis.clients.jedis.Jedis)35 Set (java.util.Set)12 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)12 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)6 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)5 List (java.util.List)4 Response (redis.clients.jedis.Response)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 JedisPool (redis.clients.jedis.JedisPool)3 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)3 Protocol (redis.clients.jedis.Protocol)2 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 Account (io.vertigo.account.account.Account)1 AccountGroup (io.vertigo.account.account.AccountGroup)1 HashMap (java.util.HashMap)1