summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-07-27 12:29:36 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-07-27 12:30:35 +0200
commit9c3a89853cc71747c048a027b9ac583df78cd79e (patch)
treebc2dc126953fae5a15f7ae5fbfed3f63cf0d55d5
parent7ca6672338344f1e8c58232fd2726776138d7054 (diff)
downloadredis-9c3a89853cc71747c048a027b9ac583df78cd79e.tar.gz
HDEL: Abort deleting fields when hash is removed
-rw-r--r--src/t_hash.c5
-rw-r--r--tests/unit/type/hash.tcl7
2 files changed, 11 insertions, 1 deletions
diff --git a/src/t_hash.c b/src/t_hash.c
index 4b9b37d69..83ca5b275 100644
--- a/src/t_hash.c
+++ b/src/t_hash.c
@@ -403,8 +403,11 @@ void hdelCommand(redisClient *c) {
for (j = 2; j < c->argc; j++) {
if (hashTypeDelete(o,c->argv[j])) {
- if (hashTypeLength(o) == 0) dbDelete(c->db,c->argv[1]);
deleted++;
+ if (hashTypeLength(o) == 0) {
+ dbDelete(c->db,c->argv[1]);
+ break;
+ }
}
}
if (deleted) {
diff --git a/tests/unit/type/hash.tcl b/tests/unit/type/hash.tcl
index 9b043d3f3..718bc04ad 100644
--- a/tests/unit/type/hash.tcl
+++ b/tests/unit/type/hash.tcl
@@ -235,6 +235,13 @@ start_server {tags {"hash"}} {
r hgetall myhash
} {b 2}
+ test {HDEL - hash becomes empty before deleting all specified fields} {
+ r del myhash
+ r hmset myhash a 1 b 2 c 3
+ assert_equal 3 [r hdel myhash a b c d e]
+ assert_equal 0 [r exists myhash]
+ }
+
test {HEXISTS} {
set rv {}
set k [lindex [array names smallhash *] 0]