Emit the commands needed to rebuild a hash object. * The function returns 0 on error, 1 on success. */
| 1297 | /* Emit the commands needed to rebuild a hash object. |
| 1298 | * The function returns 0 on error, 1 on success. */ |
| 1299 | int rewriteHashObject(rio *r, robj *key, robj *o) { |
| 1300 | hashTypeIterator *hi; |
| 1301 | long long count = 0, items = hashTypeLength(o); |
| 1302 | |
| 1303 | hi = hashTypeInitIterator(o); |
| 1304 | while (hashTypeNext(hi) != C_ERR) { |
| 1305 | if (count == 0) { |
| 1306 | int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? |
| 1307 | AOF_REWRITE_ITEMS_PER_CMD : items; |
| 1308 | |
| 1309 | if (!rioWriteBulkCount(r,'*',2+cmd_items*2) || |
| 1310 | !rioWriteBulkString(r,"HMSET",5) || |
| 1311 | !rioWriteBulkObject(r,key)) |
| 1312 | { |
| 1313 | hashTypeReleaseIterator(hi); |
| 1314 | return 0; |
| 1315 | } |
| 1316 | } |
| 1317 | |
| 1318 | if (!rioWriteHashIteratorCursor(r, hi, OBJ_HASH_KEY) || |
| 1319 | !rioWriteHashIteratorCursor(r, hi, OBJ_HASH_VALUE)) |
| 1320 | { |
| 1321 | hashTypeReleaseIterator(hi); |
| 1322 | return 0; |
| 1323 | } |
| 1324 | if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0; |
| 1325 | items--; |
| 1326 | } |
| 1327 | |
| 1328 | hashTypeReleaseIterator(hi); |
| 1329 | |
| 1330 | return 1; |
| 1331 | } |
| 1332 | |
| 1333 | /* Helper for rewriteStreamObject() that generates a bulk string into the |
| 1334 | * AOF representing the ID 'id'. */ |
no test coverage detected