Commits

Anonymous committed 705e016 Merge

Merge branch 'unstable' of https://github.com/antirez/redis into unstable

Comments (0)

Files changed (2)

 
         count += pubsubUnsubscribeChannel(c,channel,notify);
     }
+    /* We were subscribed to nothing? Still reply to the client. */
+    if (notify && count == 0) {
+        addReply(c,shared.mbulkhdr[3]);
+        addReply(c,shared.unsubscribebulk);
+        addReply(c,shared.nullbulk);
+        addReplyLongLong(c,dictSize(c->pubsub_channels)+
+                       listLength(c->pubsub_patterns));
+    }
     dictReleaseIterator(di);
     return count;
 }
 
         count += pubsubUnsubscribePattern(c,pattern,notify);
     }
+    if (notify && count == 0) {
+        /* We were subscribed to nothing? Still reply to the client. */
+        addReply(c,shared.mbulkhdr[3]);
+        addReply(c,shared.punsubscribebulk);
+        addReply(c,shared.nullbulk);
+        addReplyLongLong(c,dictSize(c->pubsub_channels)+
+                       listLength(c->pubsub_patterns));
+    }
     return count;
 }
 

tests/unit/pubsub.tcl

         # clean up clients
         $rd1 close
     }
-}
+
+    test "PUNSUBSCRIBE and UNSUBSCRIBE should always reply." {
+        # Make sure we are not subscribed to any channel at all.
+        r punsubscribe
+        r unsubscribe
+        # Now check if the commands still reply correctly.
+        set reply1 [r punsubscribe]
+        set reply2 [r unsubscribe]
+        concat $reply1 $reply2
+    } {punsubscribe {} 0 unsubscribe {} 0}
+}