From a37d0f8b48e91d1ec50ac97ef7fa832794cf6edd Mon Sep 17 00:00:00 2001
From: antirez <antirez@gmail.com>
Date: Wed, 11 Feb 2015 10:11:28 +0100
Subject: [PATCH] SPOP with count: fix replication for code path #3.

---
 src/t_set.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/t_set.c b/src/t_set.c
index 13b642dd..c8141c3f 100644
--- a/src/t_set.c
+++ b/src/t_set.c
@@ -517,10 +517,18 @@ void spopWithCountCommand(redisClient *c) {
         si = setTypeInitIterator(set);
         while((encoding = setTypeNext(si,&objele,&llele)) != -1) {
             if (encoding == REDIS_ENCODING_INTSET) {
-                addReplyBulkLongLong(c,llele);
+                objele = createStringObjectFromLongLong(llele);
             } else {
-                addReplyBulk(c,objele);
+                incrRefCount(objele);
             }
+            addReplyBulk(c,objele);
+
+            /* Replicate/AOF this command as an SREM operation */
+            propargv[2] = objele;
+            alsoPropagate(server.sremCommand,c->db->id,propargv,3,
+                REDIS_PROPAGATE_AOF|REDIS_PROPAGATE_REPL);
+
+            decrRefCount(objele);
         }
         setTypeReleaseIterator(si);
         decrRefCount(set);