1 #ifndef __SEARCH_CTX_H 2 #define __SEARCH_CTX_H 3 4 #include <sched.h> 5 6 #include "redismodule.h" 7 #include "spec.h" 8 #include "concurrent_ctx.h" 9 #include "trie/trie_type.h" 10 #include <time.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #if defined(__FreeBSD__) || defined(__DragonFly__) 17 #define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC 18 #endif 19 20 /** Context passed to all redis related search handling functions. */ 21 typedef struct RedisSearchCtx { 22 RedisModuleCtx *redisCtx; 23 RedisModuleKey *key_; 24 IndexSpec *spec; 25 uint32_t refcount; 26 int isStatic; 27 uint64_t specId; // Unique id of the spec; used when refreshing 28 } RedisSearchCtx; 29 30 #define SEARCH_CTX_STATIC(ctx, sp) \ 31 { ctx, NULL, sp, 0, 1 } 32 33 #define SEARCH_CTX_SORTABLES(ctx) ((ctx && ctx->spec) ? ctx->spec->sortables : NULL) 34 // Create a string context on the heap 35 RedisSearchCtx *NewSearchCtx(RedisModuleCtx *ctx, RedisModuleString *indexName, bool resetTTL); 36 RedisSearchCtx *NewSearchCtxDefault(RedisModuleCtx *ctx); 37 38 RedisSearchCtx *SearchCtx_Refresh(RedisSearchCtx *sctx, RedisModuleString *keyName); 39 40 // Same as above, only from c string (null terminated) 41 RedisSearchCtx *NewSearchCtxC(RedisModuleCtx *ctx, const char *indexName, bool resetTTL); 42 43 #define SearchCtx_Incref(sctx) \ 44 ({ \ 45 (sctx)->refcount++; \ 46 sctx; \ 47 }) 48 49 #define SearchCtx_Decref(sctx) \ 50 if (!--((sctx)->refcount)) { \ 51 SearchCtx_Free(sctx); \ 52 } 53 54 void SearchCtx_Free(RedisSearchCtx *sctx); 55 #ifdef __cplusplus 56 } 57 #endif 58 #endif 59