MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_ListPop

Function RM_ListPop

src/module.cpp:2669–2680  ·  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

2667 * 2. The key was not open for writing.
2668 * 3. The key is not a list. */
2669RedisModuleString *RM_ListPop(RedisModuleKey *key, int where) {
2670 if (!(key->mode & REDISMODULE_WRITE) ||
2671 key->value == NULL ||
2672 key->value->type != OBJ_LIST) return NULL;
2673 robj *ele = listTypePop(key->value,
2674 (where == REDISMODULE_LIST_HEAD) ? QUICKLIST_HEAD : QUICKLIST_TAIL);
2675 robj *decoded = getDecodedObject(ele);
2676 decrRefCount(ele);
2677 moduleDelKeyIfEmpty(key);
2678 autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,decoded);
2679 return decoded;
2680}
2681
2682/* --------------------------------------------------------------------------
2683 * ## 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