Write either the key or the value of the currently selected item of a hash. * The 'hi' argument passes a valid Redis hash iterator. * The 'what' filed specifies if to write a key or a value and can be * either OBJ_HASH_KEY or OBJ_HASH_VALUE. * * The function returns 0 on error, non-zero on success. */
| 1176 | * |
| 1177 | * The function returns 0 on error, non-zero on success. */ |
| 1178 | static int rioWriteHashIteratorCursor(rio *r, hashTypeIterator *hi, int what) { |
| 1179 | if (hi->encoding == OBJ_ENCODING_ZIPLIST) { |
| 1180 | unsigned char *vstr = NULL; |
| 1181 | unsigned int vlen = UINT_MAX; |
| 1182 | long long vll = LLONG_MAX; |
| 1183 | |
| 1184 | hashTypeCurrentFromZiplist(hi, what, &vstr, &vlen, &vll); |
| 1185 | if (vstr) |
| 1186 | return rioWriteBulkString(r, (char*)vstr, vlen); |
| 1187 | else |
| 1188 | return rioWriteBulkLongLong(r, vll); |
| 1189 | } else if (hi->encoding == OBJ_ENCODING_HT) { |
| 1190 | sds value = hashTypeCurrentFromHashTable(hi, what); |
| 1191 | return rioWriteBulkString(r, value, sdslen(value)); |
| 1192 | } |
| 1193 | |
| 1194 | serverPanic("Unknown hash encoding"); |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | /* Emit the commands needed to rebuild a hash object. |
| 1199 | * The function returns 0 on error, 1 on success. */ |
no test coverage detected