create a new command context
| 16 | |
| 17 | // create a new command context |
| 18 | CommandCtx *CommandCtx_New |
| 19 | ( |
| 20 | RedisModuleCtx *ctx, // redis module context |
| 21 | RedisModuleBlockedClient *bc, // blocked client |
| 22 | RedisModuleString *cmd_name, // command to execute |
| 23 | RedisModuleString *query, // query string |
| 24 | GraphContext *graph_ctx, // graph context |
| 25 | ExecutorThread thread, // which thread executes this command |
| 26 | bool replicated_command, // whether this instance was spawned by a replication command |
| 27 | bool compact, // whether this query was issued with the compact flag |
| 28 | long long timeout, // the query timeout, if specified |
| 29 | bool timeout_rw, // apply timeout on both read and write queries |
| 30 | uint64_t received_ts, // command received at this UNIX timestamp |
| 31 | simple_timer_t timer // stopwatch started upon command received |
| 32 | ) { |
| 33 | CommandCtx *context = rm_malloc(sizeof(CommandCtx)); |
| 34 | |
| 35 | context->bc = bc; |
| 36 | context->ctx = ctx; |
| 37 | context->query = NULL; |
| 38 | context->thread = thread; |
| 39 | context->compact = compact; |
| 40 | context->timeout = timeout; |
| 41 | context->ref_count = ATOMIC_VAR_INIT(1); |
| 42 | context->graph_ctx = graph_ctx; |
| 43 | context->timeout_rw = timeout_rw; |
| 44 | context->received_ts = received_ts; |
| 45 | context->command_name = NULL; |
| 46 | context->replicated_command = replicated_command; |
| 47 | |
| 48 | simple_timer_copy(timer, context->timer); |
| 49 | |
| 50 | if(cmd_name) { |
| 51 | // make a copy of command name |
| 52 | const char *command_name = RedisModule_StringPtrLen(cmd_name, NULL); |
| 53 | context->command_name = rm_strdup(command_name); |
| 54 | } |
| 55 | |
| 56 | if(query) { |
| 57 | // make a copy of query |
| 58 | const char *q = RedisModule_StringPtrLen(query, NULL); |
| 59 | context->query = rm_strdup(q); |
| 60 | } |
| 61 | |
| 62 | return context; |
| 63 | } |
| 64 | |
| 65 | // increment command context reference count |
| 66 | void CommandCtx_Incref |
no test coverage detected