Get fields from an hash value. This function is called using a variable * number of arguments, alternating a field name (as a RedisModuleString * pointer) with a pointer to a RedisModuleString pointer, that is set to the * value of the field if the field exists, or NULL if the field does not exist. * At the end of the field/value-ptr pairs, NULL must be specified as last * argument to signal
| 3321 | * RedisModule_FreeString(), or by enabling automatic memory management. |
| 3322 | */ |
| 3323 | int RM_HashGet(RedisModuleKey *key, int flags, ...) { |
| 3324 | va_list ap; |
| 3325 | if (key->value && key->value->type != OBJ_HASH) return REDISMODULE_ERR; |
| 3326 | |
| 3327 | va_start(ap, flags); |
| 3328 | while(1) { |
| 3329 | RedisModuleString *field, **valueptr; |
| 3330 | int *existsptr; |
| 3331 | /* Get the field object and the value pointer to pointer. */ |
| 3332 | if (flags & REDISMODULE_HASH_CFIELDS) { |
| 3333 | char *cfield = va_arg(ap,char*); |
| 3334 | if (cfield == NULL) break; |
| 3335 | field = createRawStringObject(cfield,strlen(cfield)); |
| 3336 | } else { |
| 3337 | field = va_arg(ap,RedisModuleString*); |
| 3338 | if (field == NULL) break; |
| 3339 | } |
| 3340 | |
| 3341 | /* Query the hash for existence or value object. */ |
| 3342 | if (flags & REDISMODULE_HASH_EXISTS) { |
| 3343 | existsptr = va_arg(ap,int*); |
| 3344 | if (key->value) |
| 3345 | *existsptr = hashTypeExists(key->value,szFromObj(field)); |
| 3346 | else |
| 3347 | *existsptr = 0; |
| 3348 | } else { |
| 3349 | valueptr = va_arg(ap,RedisModuleString**); |
| 3350 | if (key->value) { |
| 3351 | *valueptr = hashTypeGetValueObject(key->value,szFromObj(field)); |
| 3352 | if (*valueptr) { |
| 3353 | robj *decoded = getDecodedObject(*valueptr); |
| 3354 | decrRefCount(*valueptr); |
| 3355 | *valueptr = decoded; |
| 3356 | } |
| 3357 | if (*valueptr) |
| 3358 | autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,*valueptr); |
| 3359 | } else { |
| 3360 | *valueptr = NULL; |
| 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | /* Cleanup */ |
| 3365 | if (flags & REDISMODULE_HASH_CFIELDS) decrRefCount(field); |
| 3366 | } |
| 3367 | va_end(ap); |
| 3368 | return REDISMODULE_OK; |
| 3369 | } |
| 3370 | |
| 3371 | /* -------------------------------------------------------------------------- |
| 3372 | * ## Key API for Stream type |
nothing calls this directly
no test coverage detected