Added transactions support

This commit is contained in:
Jonathan Leibiusky
2010-07-05 00:35:47 -03:00
parent cc26791c69
commit 81cc2cec8e
11 changed files with 1196 additions and 192 deletions

View File

@@ -8,14 +8,14 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Client;
import redis.clients.jedis.Connection;
public class ClientTest extends Assert {
private Client client;
public class ConnectionTest extends Assert {
private Connection client;
@Before
public void setUp() throws Exception {
client = new Client();
client = new Connection();
}
@After

View File

@@ -207,7 +207,7 @@ public class ListCommandsTest extends Assert {
String element = jedis.rpoplpush("foo", "dst");
assertEquals("c", element);
List<String> srcExpected = new ArrayList<String>();
srcExpected.add("a");
srcExpected.add("b");

View File

@@ -0,0 +1,64 @@
package redis.clients.jedis.tests.commands;
import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisException;
import redis.clients.jedis.Transaction;
import redis.clients.jedis.TransactionBlock;
public class TransactionCommandsTest extends Assert {
private Jedis jedis;
@Before
public void setUp() throws Exception {
jedis = new Jedis("localhost");
jedis.connect();
}
@After
public void tearDown() throws Exception {
jedis.flushDB();
jedis.disconnect();
}
@Test
public void multi() throws JedisException {
Transaction trans = jedis.multi();
String status = trans.sadd("foo", "a");
assertEquals("QUEUED", status);
status = trans.sadd("foo", "b");
assertEquals("QUEUED", status);
status = trans.scard("foo");
assertEquals("QUEUED", status);
trans.exec();
//TODO: check for exec response
}
@Test
public void multiBlock() throws JedisException {
jedis.multi(new TransactionBlock() {
public void execute() throws JedisException {
String status = sadd("foo", "a");
assertEquals("QUEUED", status);
status = sadd("foo", "b");
assertEquals("QUEUED", status);
status = scard("foo");
assertEquals("QUEUED", status);
}
});
//TODO: check what happens when throwind an exception
}
}