Added watch command
This commit is contained in:
@@ -375,4 +375,8 @@ public class Client extends Connection {
|
||||
public void exec() throws JedisException {
|
||||
sendCommand("EXEC");
|
||||
}
|
||||
|
||||
public void watch(String key) throws JedisException {
|
||||
sendCommand("WATCH", key);
|
||||
}
|
||||
}
|
||||
@@ -486,4 +486,9 @@ public class Jedis {
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
public String watch(String key) throws JedisException {
|
||||
client.watch(key);
|
||||
return client.getStatusCodeReply();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis.tests.commands;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -72,4 +74,22 @@ public class TransactionCommandsTest extends Assert {
|
||||
expected.add(2);
|
||||
assertEquals(expected, response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void watch() throws JedisException, UnknownHostException,
|
||||
IOException {
|
||||
jedis.watch("mykey");
|
||||
String val = jedis.get("mykey");
|
||||
val = "foo";
|
||||
Transaction t = jedis.multi();
|
||||
|
||||
Jedis nj = new Jedis("localhost");
|
||||
nj.connect();
|
||||
nj.set("mykey", "bar");
|
||||
nj.disconnect();
|
||||
|
||||
t.set("mykey", val);
|
||||
List<Object> resp = t.exec();
|
||||
assertEquals(new ArrayList<Object>(), resp);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user