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