Regression tests for SETNX and MSETNX bugs added

This commit is contained in:
antirez 2009-12-06 01:16:12 +01:00
parent 906573e78d
commit 5acdc75d66
2 changed files with 15 additions and 1 deletions

View File

@ -2978,7 +2978,7 @@ static void echoCommand(redisClient *c) {
static void setGenericCommand(redisClient *c, int nx) { static void setGenericCommand(redisClient *c, int nx) {
int retval; int retval;
lookupKeyWrite(c->db,c->argv[1]); deleteIfVolatile(c->db,c->argv[1]);
retval = dictAdd(c->db->dict,c->argv[1],c->argv[2]); retval = dictAdd(c->db->dict,c->argv[1],c->argv[2]);
if (retval == DICT_ERR) { if (retval == DICT_ERR) {
if (!nx) { if (!nx) {

View File

@ -165,6 +165,13 @@ proc main {server port} {
$r get novar2 $r get novar2
} {foobared} } {foobared}
test {SETNX will overwrite EXPIREing key} {
$r set x 10
$r expire x 10000
$r setnx x 20
$r get x
} {20}
test {EXISTS} { test {EXISTS} {
set res {} set res {}
$r set newkey test $r set newkey test
@ -901,6 +908,13 @@ proc main {server port} {
list [$r msetnx x1 xxx y2 yyy] [$r get x1] [$r get y2] list [$r msetnx x1 xxx y2 yyy] [$r get x1] [$r get y2]
} {1 xxx yyy} } {1 xxx yyy}
test {MSETNX should remove all the volatile keys even on failure} {
$r mset x 1 y 2 z 3
$r expire y 10000
$r expire z 10000
list [$r msetnx x A y B z C] [$r mget x y z]
} {0 {1 {} {}}}
test {ZSET basic ZADD and score update} { test {ZSET basic ZADD and score update} {
$r zadd ztmp 10 x $r zadd ztmp 10 x
$r zadd ztmp 20 y $r zadd ztmp 20 y