Added watch command
This commit is contained in:
@@ -375,4 +375,8 @@ public class Client extends Connection {
|
|||||||
public void exec() throws JedisException {
|
public void exec() throws JedisException {
|
||||||
sendCommand("EXEC");
|
sendCommand("EXEC");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void watch(String key) throws JedisException {
|
||||||
|
sendCommand("WATCH", key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -486,4 +486,9 @@ public class Jedis {
|
|||||||
client.disconnect();
|
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;
|
package redis.clients.jedis.tests.commands;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -72,4 +74,22 @@ public class TransactionCommandsTest extends Assert {
|
|||||||
expected.add(2);
|
expected.add(2);
|
||||||
assertEquals(expected, response);
|
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