Skip to content

Commit

Permalink
Don't execute queries from Lua or MULTI/EXEC blocks (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreylovitz authored and swilly22 committed Nov 12, 2018
1 parent f35ce04 commit 75ab893
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/commands/cmd_bulk_insert.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ void _MGraph_BulkInsert(void *args) {

int MGraph_BulkInsert(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if (argc < 3) return RedisModule_WrongArity(ctx);

// Return immediately if invocation context is Lua or a MULTI/EXEC block
int flags = RedisModule_GetContextFlags(ctx);
if (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA)) {
RedisModule_ReplyWithError(ctx, "RedisGraph commands may not be called from non-blocking contexts.");
return REDISMODULE_OK;
}

// Prepare context.
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx, NULL, NULL, NULL, 0);
BulkInsertContext *context = BulkInsertContext_New(ctx, bc, argv, argc);
Expand Down
7 changes: 7 additions & 0 deletions src/commands/cmd_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ void _MGraph_Delete(void *args) {
int MGraph_Delete(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if (argc != 2) return RedisModule_WrongArity(ctx);

// Return immediately if invocation context is Lua or a MULTI/EXEC block
int flags = RedisModule_GetContextFlags(ctx);
if (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA)) {
RedisModule_ReplyWithError(ctx, "RedisGraph commands may not be called from non-blocking contexts.");
return REDISMODULE_OK;
}

// Construct delete operation context.
RedisModuleString *graph_name = argv[1];
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx, NULL, NULL, NULL, 0);
Expand Down
7 changes: 7 additions & 0 deletions src/commands/cmd_explain.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
int MGraph_Explain(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
if (argc < 3) return RedisModule_WrongArity(ctx);

// Return immediately if invocation context is Lua or a MULTI/EXEC block
int flags = RedisModule_GetContextFlags(ctx);
if (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA)) {
RedisModule_ReplyWithError(ctx, "RedisGraph commands may not be called from non-blocking contexts.");
return REDISMODULE_OK;
}

const char *query = RedisModule_StringPtrLen(argv[2], NULL);

/* Parse query, get AST. */
Expand Down
7 changes: 7 additions & 0 deletions src/commands/cmd_query.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ int MGraph_Query(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
double tic[2];
if (argc < 3) return RedisModule_WrongArity(ctx);

// Return immediately if invocation context is Lua or a MULTI/EXEC block
int flags = RedisModule_GetContextFlags(ctx);
if (flags & (REDISMODULE_CTX_FLAGS_MULTI | REDISMODULE_CTX_FLAGS_LUA)) {
RedisModule_ReplyWithError(ctx, "RedisGraph commands may not be called from non-blocking contexts.");
return REDISMODULE_OK;
}

simple_tic(tic);

// Parse AST.
Expand Down

0 comments on commit 75ab893

Please sign in to comment.