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
| 2330 | * call RedisModule_CloseKey() and RedisModule_KeyType() on a NULL |
| 2331 | * value. */ |
| 2332 | void *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). */ |
| 2354 | static void moduleCloseKey(RedisModuleKey *key) { |
nothing calls this directly
no test coverage detected