Emit the commands needed to rebuild a hash object. * The function returns 0 on error, 1 on success. */
| 1198 | /* Emit the commands needed to rebuild a hash object. |
| 1199 | * The function returns 0 on error, 1 on success. */ |
| 1200 | int rewriteHashObject(rio *r, robj *key, robj *o) { |
| 1201 | hashTypeIterator *hi; |
| 1202 | long long count = 0, items = hashTypeLength(o); |
| 1203 | |
| 1204 | hi = hashTypeInitIterator(o); |
| 1205 | while (hashTypeNext(hi) != C_ERR) { |
| 1206 | if (count == 0) { |
| 1207 | int cmd_items = (items > AOF_REWRITE_ITEMS_PER_CMD) ? |
| 1208 | AOF_REWRITE_ITEMS_PER_CMD : items; |
| 1209 | |
| 1210 | if (!rioWriteBulkCount(r,'*',2+cmd_items*2) || |
| 1211 | !rioWriteBulkString(r,"HMSET",5) || |
| 1212 | !rioWriteBulkObject(r,key)) |
| 1213 | { |
| 1214 | hashTypeReleaseIterator(hi); |
| 1215 | return 0; |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | if (!rioWriteHashIteratorCursor(r, hi, OBJ_HASH_KEY) || |
| 1220 | !rioWriteHashIteratorCursor(r, hi, OBJ_HASH_VALUE)) |
| 1221 | { |
| 1222 | hashTypeReleaseIterator(hi); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | if (++count == AOF_REWRITE_ITEMS_PER_CMD) count = 0; |
| 1226 | items--; |
| 1227 | } |
| 1228 | |
| 1229 | hashTypeReleaseIterator(hi); |
| 1230 | |
| 1231 | return 1; |
| 1232 | } |
| 1233 | |
| 1234 | /* Helper for rewriteStreamObject() that generates a bulk string into the |
| 1235 | * AOF representing the ID 'id'. */ |
no test coverage detected