Emit the commands needed to rebuild a list object. * The function returns 0 on error, 1 on success. */
| 1090 | /* Emit the commands needed to rebuild a list object. |
| 1091 | * The function returns 0 on error, 1 on success. */ |
| 1092 | int rewriteListObject(rio *r, robj *key, robj *o) { |
| 1093 | long long count = 0, items = listTypeLength(o); |
| 1094 | |
| 1095 | if (o->encoding == OBJ_ENCODING_QUICKLIST) { |
| 1096 | quicklist *list = (quicklist*)ptrFromObj(o); |
| 1097 | quicklistIter *li = quicklistGetIterator(list, AL_START_HEAD); |
| 1098 | quicklistEntry entry; |
| 1099 | |
| 1100 | while (quicklistNext(li,&entry)) { |
| 1101 | if (count == 0) { |
| 1102 | int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? |
| 1103 | AOF_REWRITE_ITEMS_PER_CMD : items; |
| 1104 | if (!rioWriteBulkCount(r,'*',2+cmd_items) || |
| 1105 | !rioWriteBulkString(r,"RPUSH",5) || |
| 1106 | !rioWriteBulkObject(r,key)) |
| 1107 | { |
| 1108 | quicklistReleaseIterator(li); |
| 1109 | return 0; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | if (entry.value) { |
| 1114 | if (!rioWriteBulkString(r,(char*)entry.value,entry.sz)) { |
| 1115 | quicklistReleaseIterator(li); |
| 1116 | return 0; |
| 1117 | } |
| 1118 | } else { |
| 1119 | if (!rioWriteBulkLongLong(r,entry.longval)) { |
| 1120 | quicklistReleaseIterator(li); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | } |
| 1124 | if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0; |
| 1125 | items--; |
| 1126 | } |
| 1127 | quicklistReleaseIterator(li); |
| 1128 | } else { |
| 1129 | serverPanic("Unknown list encoding"); |
| 1130 | } |
| 1131 | return 1; |
| 1132 | } |
| 1133 | |
| 1134 | /* Emit the commands needed to rebuild a set object. |
| 1135 | * The function returns 0 on error, 1 on success. */ |
no test coverage detected