_GraphContext_Create tries to get a graph context and if it does not exists, create a new one the try-get-create flow is done when module global lock is acquired to enforce consistency while BGSave is called
| 141 | // the try-get-create flow is done when module global lock is acquired |
| 142 | // to enforce consistency while BGSave is called |
| 143 | static GraphContext *_GraphContext_Create |
| 144 | ( |
| 145 | RedisModuleCtx *ctx, |
| 146 | const char *graph_name |
| 147 | ) { |
| 148 | // create and initialize a graph context |
| 149 | GraphContext *gc = GraphContext_New(graph_name); |
| 150 | RedisModuleString *graphID = RedisModule_CreateString(ctx, graph_name, |
| 151 | strlen(graph_name)); |
| 152 | |
| 153 | RedisModuleKey *key = RedisModule_OpenKey(ctx, graphID, REDISMODULE_WRITE); |
| 154 | |
| 155 | // set value in key |
| 156 | RedisModule_ModuleTypeSetValue(key, GraphContextRedisModuleType, gc); |
| 157 | |
| 158 | // register graph context for BGSave |
| 159 | GraphContext_RegisterWithModule(gc); |
| 160 | |
| 161 | RedisModule_FreeString(ctx, graphID); |
| 162 | RedisModule_CloseKey(key); |
| 163 | |
| 164 | return gc; |
| 165 | } |
| 166 | |
| 167 | GraphContext *GraphContext_Retrieve |
| 168 | ( |
no test coverage detected