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. */
| 2667 | * 2. The key was not open for writing. |
| 2668 | * 3. The key is not a list. */ |
| 2669 | RedisModuleString *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 |
nothing calls this directly
no test coverage detected