| 290 | } |
| 291 | |
| 292 | sds writeNestedHashAsJson(sds output, robj_roptr o) { |
| 293 | if (o->type == OBJ_STRING) { |
| 294 | output = writeJsonValue(output, (sds)szFromObj(o)); |
| 295 | } else if (o->type == OBJ_LIST) { |
| 296 | unsigned char *zl = (unsigned char*)ptrFromObj(o); |
| 297 | output = sdscat(output, "["); |
| 298 | unsigned char *p = ziplistIndex(zl, ZIPLIST_HEAD); |
| 299 | bool fFirst = true; |
| 300 | while (p != nullptr) { |
| 301 | unsigned char *str; |
| 302 | unsigned int len; |
| 303 | long long lval; |
| 304 | if (ziplistGet(p, &str, &len, &lval)) { |
| 305 | char rgT[128]; |
| 306 | if (str == nullptr) { |
| 307 | len = ll2string(rgT, 128, lval); |
| 308 | str = (unsigned char*)rgT; |
| 309 | } |
| 310 | if (!fFirst) |
| 311 | output = sdscat(output, ","); |
| 312 | fFirst = false; |
| 313 | output = writeJsonValue(output, (const char*)str, len); |
| 314 | } |
| 315 | p = ziplistNext(zl, p); |
| 316 | } |
| 317 | output = sdscat(output, "]"); |
| 318 | } else { |
| 319 | output = sdscat(output, "{"); |
| 320 | dictIterator *di = dictGetIterator((dict*)ptrFromObj(o)); |
| 321 | dictEntry *de; |
| 322 | bool fFirst = true; |
| 323 | while ((de = dictNext(di))) { |
| 324 | robj_roptr oT = (robj*)dictGetVal(de); |
| 325 | if (!fFirst) |
| 326 | output = sdscat(output, ","); |
| 327 | fFirst = false; |
| 328 | output = writeJsonValue(output, (sds)dictGetKey(de)); |
| 329 | output = sdscat(output, " : "); |
| 330 | output = writeNestedHashAsJson(output, oT); |
| 331 | } |
| 332 | dictReleaseIterator(di); |
| 333 | output = sdscat(output, "}"); |
| 334 | } |
| 335 | return output; |
| 336 | } |
| 337 | |
| 338 | void nhsetCommand(client *c) { |
| 339 | if (c->argc < 3) |
no test coverage detected