MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_HashGet

Function RM_HashGet

app/redis-6.2.6/src/module.c:3235–3281  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

3233 * RedisModule_FreeString(), or by enabling automatic memory management.
3234 */
3235int RM_HashGet(RedisModuleKey *key, int flags, ...) {
3236 va_list ap;
3237 if (key->value && key->value->type != OBJ_HASH) return REDISMODULE_ERR;
3238
3239 va_start(ap, flags);
3240 while(1) {
3241 RedisModuleString *field, **valueptr;
3242 int *existsptr;
3243 /* Get the field object and the value pointer to pointer. */
3244 if (flags & REDISMODULE_HASH_CFIELDS) {
3245 char *cfield = va_arg(ap,char*);
3246 if (cfield == NULL) break;
3247 field = createRawStringObject(cfield,strlen(cfield));
3248 } else {
3249 field = va_arg(ap,RedisModuleString*);
3250 if (field == NULL) break;
3251 }
3252
3253 /* Query the hash for existence or value object. */
3254 if (flags & REDISMODULE_HASH_EXISTS) {
3255 existsptr = va_arg(ap,int*);
3256 if (key->value)
3257 *existsptr = hashTypeExists(key->value,field->ptr);
3258 else
3259 *existsptr = 0;
3260 } else {
3261 valueptr = va_arg(ap,RedisModuleString**);
3262 if (key->value) {
3263 *valueptr = hashTypeGetValueObject(key->value,field->ptr);
3264 if (*valueptr) {
3265 robj *decoded = getDecodedObject(*valueptr);
3266 decrRefCount(*valueptr);
3267 *valueptr = decoded;
3268 }
3269 if (*valueptr)
3270 autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,*valueptr);
3271 } else {
3272 *valueptr = NULL;
3273 }
3274 }
3275
3276 /* Cleanup */
3277 if (flags & REDISMODULE_HASH_CFIELDS) decrRefCount(field);
3278 }
3279 va_end(ap);
3280 return REDISMODULE_OK;
3281}
3282
3283/* --------------------------------------------------------------------------
3284 * ## Key API for Stream type

Callers

nothing calls this directly

Calls 6

createRawStringObjectFunction · 0.85
hashTypeExistsFunction · 0.85
hashTypeGetValueObjectFunction · 0.85
getDecodedObjectFunction · 0.85
decrRefCountFunction · 0.85
autoMemoryAddFunction · 0.85

Tested by

no test coverage detected