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

Function RM_OpenKey

src/module.cpp:2332–2351  ·  view source on GitHub ↗

Return an handle representing a Redis key, so that it is possible * to call other APIs with the key handle as argument to perform * operations on the key. * * The return value is the handle representing the key, that must be * closed with RM_CloseKey(). * * If the key does not exist and WRITE mode is requested, the handle * is still returned, since it is possible to perform operations on

Source from the content-addressed store, hash-verified

2330 * call RedisModule_CloseKey() and RedisModule_KeyType() on a NULL
2331 * value. */
2332void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
2333 RedisModuleKey *kp;
2334 robj *value;
2335 int flags = mode & REDISMODULE_OPEN_KEY_NOTOUCH? LOOKUP_NOTOUCH: 0;
2336
2337 if (mode & REDISMODULE_WRITE) {
2338 value = lookupKeyWriteWithFlags(ctx->client->db,keyname, flags);
2339 } else {
2340 value = lookupKeyReadWithFlags(ctx->client->db,keyname, flags).unsafe_robjcast();
2341 if (value == NULL) {
2342 return NULL;
2343 }
2344 }
2345
2346 /* Setup the key handle. */
2347 kp = (RedisModuleKey*)zmalloc(sizeof(*kp));
2348 moduleInitKey(kp, ctx, keyname, value, mode);
2349 autoMemoryAdd(ctx,REDISMODULE_AM_KEY,kp);
2350 return (void*)kp;
2351}
2352
2353/* Destroy a RedisModuleKey struct (freeing is the responsibility of the caller). */
2354static void moduleCloseKey(RedisModuleKey *key) {

Callers

nothing calls this directly

Calls 6

lookupKeyWriteWithFlagsFunction · 0.85
lookupKeyReadWithFlagsFunction · 0.85
zmallocFunction · 0.85
moduleInitKeyFunction · 0.85
autoMemoryAddFunction · 0.85
unsafe_robjcastMethod · 0.80

Tested by

no test coverage detected