this callback invokes once rename for a graph is done since the key value is a graph context which saves the name of the graph for later key accesses this data must be consistent with the key name otherwise the graph context will remain with the previous graph name and a key access to this name might yield an empty key or wrong value this method changes the graph name value at the graph context to
| 47 | // this method changes the graph name value at the graph context to be |
| 48 | // consistent with the key name |
| 49 | static int _GenericKeyspaceHandler |
| 50 | ( |
| 51 | RedisModuleCtx *ctx, |
| 52 | int type, |
| 53 | const char *event, |
| 54 | RedisModuleString *key_name |
| 55 | ) { |
| 56 | if(type != REDISMODULE_NOTIFY_GENERIC) { |
| 57 | return REDISMODULE_OK; |
| 58 | } |
| 59 | |
| 60 | if(strcasecmp(event, "RENAME_TO") == 0) { |
| 61 | RedisModuleKey *key = RedisModule_OpenKey(ctx, key_name, |
| 62 | REDISMODULE_WRITE); |
| 63 | if(RedisModule_ModuleTypeGetType(key) == GraphContextRedisModuleType) { |
| 64 | GraphContext *gc = RedisModule_ModuleTypeGetValue(key); |
| 65 | size_t len; |
| 66 | const char *new_name = RedisModule_StringPtrLen(key_name, &len); |
| 67 | GraphContext_Rename(ctx, gc, new_name); |
| 68 | } |
| 69 | RedisModule_CloseKey(key); |
| 70 | } |
| 71 | |
| 72 | else if(strcasecmp(event, "DEL") == 0) { |
| 73 | // TODO: in Redis 7.2 we could use REDISMODULE_EVENT_KEY to register |
| 74 | // for a more convenient key event notification |
| 75 | const char *graph_name = RedisModule_StringPtrLen(key_name, NULL); |
| 76 | Globals_RemoveGraphByName(graph_name); |
| 77 | } |
| 78 | |
| 79 | return REDISMODULE_OK; |
| 80 | } |
| 81 | |
| 82 | //------------------------------------------------------------------------------ |
| 83 | // Meta keys API |
nothing calls this directly
no test coverage detected