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

Function RM_ListPop

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

Pop an element from the list, and returns it as a module string object * that the user should be free with RM_FreeString() or by enabling * automatic memory. 'where' specifies if the element should be popped from * head or tail. The command returns NULL if: * * 1. The list is empty. * 2. The key was not open for writing. * 3. The key is not a list. */

Source from the content-addressed store, hash-verified

2579 * 2. The key was not open for writing.
2580 * 3. The key is not a list. */
2581RedisModuleString *RM_ListPop(RedisModuleKey *key, int where) {
2582 if (!(key->mode & REDISMODULE_WRITE) ||
2583 key->value == NULL ||
2584 key->value->type != OBJ_LIST) return NULL;
2585 robj *ele = listTypePop(key->value,
2586 (where == REDISMODULE_LIST_HEAD) ? QUICKLIST_HEAD : QUICKLIST_TAIL);
2587 robj *decoded = getDecodedObject(ele);
2588 decrRefCount(ele);
2589 moduleDelKeyIfEmpty(key);
2590 autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,decoded);
2591 return decoded;
2592}
2593
2594/* --------------------------------------------------------------------------
2595 * ## Key API for Sorted Set type

Callers

nothing calls this directly

Calls 5

listTypePopFunction · 0.85
getDecodedObjectFunction · 0.85
decrRefCountFunction · 0.85
moduleDelKeyIfEmptyFunction · 0.85
autoMemoryAddFunction · 0.85

Tested by

no test coverage detected