Emit the commands needed to rebuild a set object. * The function returns 0 on error, 1 on success. */
| 1134 | /* Emit the commands needed to rebuild a set object. |
| 1135 | * The function returns 0 on error, 1 on success. */ |
| 1136 | int rewriteSetObject(rio *r, robj *key, robj *o) { |
| 1137 | long long count = 0, items = setTypeSize(o); |
| 1138 | |
| 1139 | if (o->encoding == OBJ_ENCODING_INTSET) { |
| 1140 | int ii = 0; |
| 1141 | int64_t llval; |
| 1142 | |
| 1143 | while(intsetGet((intset*)ptrFromObj(o),ii++,&llval)) { |
| 1144 | if (count == 0) { |
| 1145 | int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? |
| 1146 | AOF_REWRITE_ITEMS_PER_CMD : items; |
| 1147 | |
| 1148 | if (!rioWriteBulkCount(r,'*',2+cmd_items) || |
| 1149 | !rioWriteBulkString(r,"SADD",4) || |
| 1150 | !rioWriteBulkObject(r,key)) |
| 1151 | { |
| 1152 | return 0; |
| 1153 | } |
| 1154 | } |
| 1155 | if (!rioWriteBulkLongLong(r,llval)) return 0; |
| 1156 | if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0; |
| 1157 | items--; |
| 1158 | } |
| 1159 | } else if (o->encoding == OBJ_ENCODING_HT) { |
| 1160 | dictIterator *di = dictGetIterator((dict*)ptrFromObj(o)); |
| 1161 | dictEntry *de; |
| 1162 | |
| 1163 | while((de = dictNext(di)) != NULL) { |
| 1164 | sds ele = (sds)dictGetKey(de); |
| 1165 | if (count == 0) { |
| 1166 | int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? |
| 1167 | AOF_REWRITE_ITEMS_PER_CMD : items; |
| 1168 | |
| 1169 | if (!rioWriteBulkCount(r,'*',2+cmd_items) || |
| 1170 | !rioWriteBulkString(r,"SADD",4) || |
| 1171 | !rioWriteBulkObject(r,key)) |
| 1172 | { |
| 1173 | dictReleaseIterator(di); |
| 1174 | return 0; |
| 1175 | } |
| 1176 | } |
| 1177 | if (!rioWriteBulkString(r,ele,sdslen(ele))) { |
| 1178 | dictReleaseIterator(di); |
| 1179 | return 0; |
| 1180 | } |
| 1181 | if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0; |
| 1182 | items--; |
| 1183 | } |
| 1184 | dictReleaseIterator(di); |
| 1185 | } else { |
| 1186 | serverPanic("Unknown set encoding"); |
| 1187 | } |
| 1188 | return 1; |
| 1189 | } |
| 1190 | |
| 1191 | /* Emit the commands needed to rebuild a sorted set object. |
| 1192 | * The function returns 0 on error, 1 on success. */ |
no test coverage detected