-
- /* Create temp file */
- snprintf(buf,sizeof(buf),"redis-dump-%d.tmp",getpid());
- fp = fopen(buf,"w+");
- if (!fp) {
- redisLog(REDIS_WARNING,"Can't open tmp file for MIGRATE: %s",
- strerror(errno));
- addReplyErrorFormat(c,"DUMP failed, tmp file creation error: %s.",
- strerror(errno));
- return;
- }
- unlink(buf);
-
- /* Dump the serailized object and read it back in memory.
- * We prefix it with a one byte containing the type ID.
- * This is the serialization format understood by RESTORE. */
- if (rdbSaveObject(fp,o) == -1) goto file_wr_err;
- payload_len = ftello(fp);
- if (fseeko(fp,0,SEEK_SET) == -1) goto file_rd_err;
- dump = sdsnewlen(NULL,payload_len+1);
- if (payload_len && fread(dump+1,payload_len,1,fp) != 1) goto file_rd_err;
- fclose(fp);
- type = o->type;
- if (type == REDIS_LIST && o->encoding == REDIS_ENCODING_ZIPLIST)
- type = REDIS_LIST_ZIPLIST;
- else if (type == REDIS_HASH && o->encoding == REDIS_ENCODING_ZIPMAP)
- type = REDIS_HASH_ZIPMAP;
- else if (type == REDIS_SET && o->encoding == REDIS_ENCODING_INTSET)
- type = REDIS_SET_INTSET;
- else
- type = o->type;
- dump[0] = type;
+
+ /* Serialize the object in a RDB-like format. It consist of an object type
+ * byte followed by the serialized object. This is understood by RESTORE. */
+ rioInitWithBuffer(&payload,sdsempty());
+ redisAssertWithInfo(c,NULL,rdbSaveObjectType(&payload,o));
+ redisAssertWithInfo(c,NULL,rdbSaveObject(&payload,o));