/* HELLOTYPE.RANGE key first count */ int HelloTypeRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ if (argc != 4) return RedisModule_WrongArity(ctx); RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1], REDISMODULE_READ|REDISMODULE_WRITE); int type = RedisModule_KeyType(key); if (type != REDISMODULE_KEYTYPE_EMPTY && RedisModule_ModuleTypeGetType(key) != HelloType) { return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE); } long long first, count; if (RedisModule_StringToLongLong(argv[2],&first) != REDISMODULE_OK || RedisModule_StringToLongLong(argv[3],&count) != REDISMODULE_OK || first < 0 || count < 0) { return RedisModule_ReplyWithError(ctx, "ERR invalid first or count parameters"); } struct HelloTypeObject *hto = RedisModule_ModuleTypeGetValue(key); struct HelloTypeNode *node = hto ? hto->head : NULL; RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN); long long arraylen = 0; while(node && count--) { RedisModule_ReplyWithLongLong(ctx,node->value); arraylen++; node = node->next; } RedisModule_ReplySetArrayLength(ctx,arraylen); return REDISMODULE_OK; }
/* HELLO.LEXRANGE key min_lex max_lex min_age max_age * This command expects a sorted set stored at key in the following form: * - All the elements have score 0. * - Elements are pairs of "<name>:<age>", for example "Anna:52". * The command will return all the sorted set items that are lexicographically * between the specified range (using the same format as ZRANGEBYLEX) * and having an age between min_age and max_age. */ int HelloLexRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { RedisModule_AutoMemory(ctx); /* Use automatic memory management. */ if (argc != 6) return RedisModule_WrongArity(ctx); RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1], REDISMODULE_READ|REDISMODULE_WRITE); if (RedisModule_KeyType(key) != REDISMODULE_KEYTYPE_ZSET) { return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE); } if (RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]) != REDISMODULE_OK) { return RedisModule_ReplyWithError(ctx,"invalid range"); } int arraylen = 0; RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN); while(!RedisModule_ZsetRangeEndReached(key)) { double score; RedisModuleString *ele = RedisModule_ZsetRangeCurrentElement(key,&score); RedisModule_ReplyWithString(ctx,ele); RedisModule_FreeString(ctx,ele); RedisModule_ZsetRangeNext(key); arraylen++; } RedisModule_ZsetRangeStop(key); RedisModule_ReplySetArrayLength(ctx,arraylen); RedisModule_CloseKey(key); return REDISMODULE_OK; }
void SpellCheck_Reply(SpellCheckCtx *scCtx, QueryAST *q) { if (!SpellCheck_CheckTermDictsExistance(scCtx)) { return; } RedisModule_ReplyWithArray(scCtx->sctx->redisCtx, REDISMODULE_POSTPONED_ARRAY_LEN); if (scCtx->fullScoreInfo) { // sending the total number of docs for the ability to calculate score on cluster RedisModule_ReplyWithLongLong(scCtx->sctx->redisCtx, scCtx->sctx->spec->docs.size - 1); } QueryNode_ForEach(q->root, forEachCallback, scCtx, 1); RedisModule_ReplySetArrayLength(scCtx->sctx->redisCtx, scCtx->results + (scCtx->fullScoreInfo ? 1 : 0)); }
/* Serialize all the tags in the index to the redis client */ void TagIndex_SerializeValues(TagIndex *idx, RedisModuleCtx *ctx) { TrieMapIterator *it = TrieMap_Iterate(idx->values, "", 0); char *str; tm_len_t slen; void *ptr; RedisModule_ReplyWithArray(ctx, REDISMODULE_POSTPONED_ARRAY_LEN); long long count = 0; while (TrieMapIterator_Next(it, &str, &slen, &ptr)) { ++count; RedisModule_ReplyWithStringBuffer(ctx, str, slen); } RedisModule_ReplySetArrayLength(ctx, count); TrieMapIterator_Free(it); }