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

Function RM_OpenKey

app/redis-6.2.6/src/module.c:2251–2270  ·  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

2249 * call RedisModule_CloseKey() and RedisModule_KeyType() on a NULL
2250 * value. */
2251void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
2252 RedisModuleKey *kp;
2253 robj *value;
2254 int flags = mode & REDISMODULE_OPEN_KEY_NOTOUCH? LOOKUP_NOTOUCH: 0;
2255
2256 if (mode & REDISMODULE_WRITE) {
2257 value = lookupKeyWriteWithFlags(ctx->client->db,keyname, flags);
2258 } else {
2259 value = lookupKeyReadWithFlags(ctx->client->db,keyname, flags);
2260 if (value == NULL) {
2261 return NULL;
2262 }
2263 }
2264
2265 /* Setup the key handle. */
2266 kp = zmalloc(sizeof(*kp));
2267 moduleInitKey(kp, ctx, keyname, value, mode);
2268 autoMemoryAdd(ctx,REDISMODULE_AM_KEY,kp);
2269 return (void*)kp;
2270}
2271
2272/* Destroy a RedisModuleKey struct (freeing is the responsibility of the caller). */
2273static void moduleCloseKey(RedisModuleKey *key) {

Callers

nothing calls this directly

Calls 5

lookupKeyWriteWithFlagsFunction · 0.85
lookupKeyReadWithFlagsFunction · 0.85
zmallocFunction · 0.85
moduleInitKeyFunction · 0.85
autoMemoryAddFunction · 0.85

Tested by

no test coverage detected