Search in sources :

Example 26 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 27 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 28 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 29 with Transaction

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

the class TransactionCommandsTest method discard.

@Test
public void discard() {
    Transaction t = jedis.multi();
    String status = t.discard();
    assertEquals("OK", status);
}
Also used : Transaction(redis.clients.jedis.Transaction) Test(org.junit.Test)

Example 30 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)42 Test (org.junit.Test)32 Jedis (redis.clients.jedis.Jedis)19 Set (java.util.Set)7 JedisDataException (redis.clients.jedis.exceptions.JedisDataException)6 GenericObjectPoolConfig (org.apache.commons.pool2.impl.GenericObjectPoolConfig)4 JedisException (redis.clients.jedis.exceptions.JedisException)4 Response (redis.clients.jedis.Response)3 ArrayList (java.util.ArrayList)2 JedisPool (redis.clients.jedis.JedisPool)2 JedisSentinelPool (redis.clients.jedis.JedisSentinelPool)2 JedisConnectionException (redis.clients.jedis.exceptions.JedisConnectionException)2 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 ResourceMetadata (org.opennms.newts.cassandra.search.ResourceMetadata)1