Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More tests for MULTI/EXEC/DISCARD goodness.

  • Loading branch information...
commit d5649d317c807aa6105e54e1265f8e16feaf4646 1 parent 1f7408f
@nicolasff authored
Showing with 37 additions and 6 deletions.
  1. +1 −1  Makefile
  2. +4 −4 redis.cpp
  3. +1 −1  redis.h
  4. +31 −0 test.cpp
View
2  Makefile
@@ -1,6 +1,6 @@
OUT=test
OBJS=test.o redis.o redisCommand.o redisResponse.o redisSortParams.o redisBuffer.o
-CPPFLAGS=-ggdb -Wall -Wextra
+CPPFLAGS=-O2 -Wall -Wextra
all: $(OUT)
View
8 redis.cpp
@@ -71,15 +71,15 @@ Client::run(Command &c, ResponseReader fun) {
}
}
-void
+Response
Client::discard() {
- Command cmd("DISCARD");
- run(cmd);
-
m_multi = false;
m_pipeline = false;
m_cmd.clear();
m_readers.clear();
+
+ Command cmd("DISCARD");
+ return run(cmd, &Client::read_status_code);
}
View
2  redis.h
@@ -134,7 +134,7 @@ class Client {
Response multi();
bool pipeline();
- void discard();
+ Response discard();
std::vector<Response> exec();
private:
View
31 test.cpp
@@ -1437,10 +1437,12 @@ testLastsave(redis::Client &redis) {
void
testMultiExec(redis::Client &redis) {
+ //empty
redis.multi();
vector<redis::Response> vret = redis.exec();
assert(vret.size() == 0);
+ // simple commands
redis.multi();
redis.set("x", "abc");
redis.set("y", "def");
@@ -1453,6 +1455,35 @@ testMultiExec(redis::Client &redis) {
assert(vret[1].type() == REDIS_BOOL && vret[1].get<bool>());
assert(vret[2].type() == REDIS_STRING && vret[2].get<string>() == "abc");
assert(vret[3].type() == REDIS_STRING && vret[3].get<string>() == "def");
+
+ // support for errors
+ redis.multi();
+ redis.del("x");
+ redis.get("x");
+ vret = redis.exec();
+ assert(vret.size() == 2);
+ assert(vret[0].type() == REDIS_LONG && vret[0].get<long>() == 1);
+ assert(vret[1].type() == REDIS_ERR);
+
+ // two multis
+ redis::Response ret = redis.multi();
+ assert(ret.type() == REDIS_BOOL && ret.get<bool>());
+ ret = redis.multi();
+ assert(ret.type() == REDIS_ERR);
+
+ // exec without multi
+ vret = redis.exec();
+ assert(vret.size() == 0);
+
+ // support for discard
+ redis.set("x", "abc");
+ redis.multi();
+ redis.del("x");
+ ret = redis.discard(); // do not execute transaction → "x" is still pointing to "abc"
+ assert(ret.type() == REDIS_BOOL && ret.get<bool>());
+
+ ret = redis.get("x");
+ assert(ret.type() == REDIS_STRING && ret.get<string>() == "abc");
}
int main() {
Please sign in to comment.
Something went wrong with that request. Please try again.