]> git.saurik.com Git - redis.git/blobdiff - src/object.c
fixed a few problems with redis-trib resharding.
[redis.git] / src / object.c
index ce13429af94df159cf51307d721f8da52e152550..c1df4d1d2ad8dc91a904223c384ba5aa8bdf3959 100644 (file)
@@ -192,6 +192,23 @@ void decrRefCount(void *obj) {
     }
 }
 
+/* This function set the ref count to zero without freeing the object.
+ * It is useful in order to pass a new object to functions incrementing
+ * the ref count of the received object. Example:
+ *
+ *    functionThatWillIncrementRefCount(resetRefCount(CreateObject(...)));
+ *
+ * Otherwise you need to resort to the less elegant pattern:
+ *
+ *    *obj = createObject(...);
+ *    functionThatWillIncrementRefCount(obj);
+ *    decrRefCount(obj);
+ */
+robj *resetRefCount(robj *obj) {
+    obj->refcount = 0;
+    return obj;
+}
+
 int checkType(redisClient *c, robj *o, int type) {
     if (o->type != type) {
         addReply(c,shared.wrongtypeerr);