MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / GraphContext_Retrieve

Function GraphContext_Retrieve

src/graph/graphcontext.c:167–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167GraphContext *GraphContext_Retrieve
168(
169 RedisModuleCtx *ctx,
170 RedisModuleString *graphID,
171 bool readOnly,
172 bool shouldCreate
173) {
174 // check if we're still replicating, if so don't allow access to the graph
175 if(aux_field_counter > 0) {
176 // the whole module is currently replicating, emit an error
177 RedisModule_ReplyWithError(ctx, "ERR RedisGraph module is currently replicating");
178 return NULL;
179 }
180
181 GraphContext *gc = NULL;
182 int rwFlag = readOnly ? REDISMODULE_READ : REDISMODULE_WRITE;
183
184 RedisModuleKey *key = RedisModule_OpenKey(ctx, graphID, rwFlag);
185 if(RedisModule_KeyType(key) == REDISMODULE_KEYTYPE_EMPTY) {
186 if(shouldCreate) {
187 // Key doesn't exist, create it.
188 const char *graphName = RedisModule_StringPtrLen(graphID, NULL);
189 gc = _GraphContext_Create(ctx, graphName);
190 } else {
191 // Key does not exist and won't be created, emit an error.
192 RedisModule_ReplyWithError(ctx, "ERR Invalid graph operation on empty key");
193 }
194 } else if(RedisModule_ModuleTypeGetType(key) == GraphContextRedisModuleType) {
195 gc = RedisModule_ModuleTypeGetValue(key);
196 } else {
197 // Key exists but is not a graph, emit an error.
198 RedisModule_ReplyWithError(ctx, REDISMODULE_ERRORMSG_WRONGTYPE);
199 }
200
201 RedisModule_CloseKey(key);
202
203 if(gc) GraphContext_IncreaseRefCount(gc);
204
205 return gc;
206}
207
208void GraphContext_MarkWriter(RedisModuleCtx *ctx, GraphContext *gc) {
209 RedisModuleString *graphID = RedisModule_CreateString(ctx, gc->graph_name, strlen(gc->graph_name));

Callers 6

Graph_EffectFunction · 0.85
CommandDispatchFunction · 0.85
Graph_BulkInsertFunction · 0.85
Graph_SlowlogFunction · 0.85
_Constraint_DropFunction · 0.85
_Constraint_CreateFunction · 0.85

Calls 2

_GraphContext_CreateFunction · 0.85

Tested by

no test coverage detected