From: Pieter Noordhuis <pcnoordhuis@gmail.com>
Date: Mon, 21 Mar 2011 22:54:35 +0000 (+0100)
Subject: Remove sorted set when empty after ZREMRANGEBY*
X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/48991620f71485a5fa056736796b620eab1387a9

Remove sorted set when empty after ZREMRANGEBY*
---

diff --git a/src/t_zset.c b/src/t_zset.c
index 03a79ce9..f630ff02 100644
--- a/src/t_zset.c
+++ b/src/t_zset.c
@@ -1012,6 +1012,7 @@ void zremrangebyscoreCommand(redisClient *c) {
 
     if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
         zobj->ptr = zzlDeleteRangeByScore(zobj->ptr,range,&deleted);
+        if (zzlLength(zobj->ptr) == 0) dbDelete(c->db,key);
     } else if (zobj->encoding == REDIS_ENCODING_RAW) {
         zset *zs = zobj->ptr;
         deleted = zslDeleteRangeByScore(zs->zsl,range,zs->dict);
@@ -1057,6 +1058,7 @@ void zremrangebyrankCommand(redisClient *c) {
     if (zobj->encoding == REDIS_ENCODING_ZIPLIST) {
         /* Correct for 1-based rank. */
         zobj->ptr = zzlDeleteRangeByRank(zobj->ptr,start+1,end+1,&deleted);
+        if (zzlLength(zobj->ptr) == 0) dbDelete(c->db,key);
     } else if (zobj->encoding == REDIS_ENCODING_RAW) {
         zset *zs = zobj->ptr;