Return a context which can be used inside threads to make Redis context * calls with certain modules APIs. If 'bc' is not NULL then the module will * be bound to a blocked client, and it will be possible to use the * `RedisModule_Reply*` family of functions to accumulate a reply for when the * client will be unblocked. Otherwise the thread safe context will be * detached by a specific client.
| 5760 | * consider using `RM_GetDetachedThreadSafeContext` which will also retain |
| 5761 | * the module ID and thus be more useful for logging. */ |
| 5762 | RedisModuleCtx *RM_GetThreadSafeContext(RedisModuleBlockedClient *bc) { |
| 5763 | RedisModuleCtx *ctx = zmalloc(sizeof(*ctx)); |
| 5764 | RedisModuleCtx empty = REDISMODULE_CTX_INIT; |
| 5765 | memcpy(ctx,&empty,sizeof(empty)); |
| 5766 | if (bc) { |
| 5767 | ctx->blocked_client = bc; |
| 5768 | ctx->module = bc->module; |
| 5769 | } |
| 5770 | ctx->flags |= REDISMODULE_CTX_THREAD_SAFE; |
| 5771 | /* Even when the context is associated with a blocked client, we can't |
| 5772 | * access it safely from another thread, so we create a fake client here |
| 5773 | * in order to keep things like the currently selected database and similar |
| 5774 | * things. */ |
| 5775 | ctx->client = createClient(NULL); |
| 5776 | if (bc) { |
| 5777 | selectDb(ctx->client,bc->dbid); |
| 5778 | if (bc->client) ctx->client->id = bc->client->id; |
| 5779 | } |
| 5780 | return ctx; |
| 5781 | } |
| 5782 | |
| 5783 | /* Return a detached thread safe context that is not associated with any |
| 5784 | * specific blocked client, but is associated with the module's context. |
nothing calls this directly
no test coverage detected