From: Pieter Noordhuis Date: Wed, 27 Jul 2011 10:29:36 +0000 (+0200) Subject: HDEL: Abort deleting fields when hash is removed X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/2d7162bb1db39bbdd80e3d2c99899f6d9ac4b2d6?ds=sidebyside HDEL: Abort deleting fields when hash is removed --- diff --git a/src/t_hash.c b/src/t_hash.c index 4b9b37d6..83ca5b27 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 9b043d3f..718bc04a 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]