Remove REDISMODULE_ prefixes and introduce compatibility header (#194)
Fix #146 Removed REDISMODULE_ prefixes from the core source code to align with the new SERVERMODULE_ naming convention. Added a new 'redismodule.h' header file to ensure full backward compatibility with existing modules. This compatibility layer maps all legacy REDISMODULE_ prefixed identifiers to their new SERVERMODULE_ equivalents, allowing existing Redis modules to function without modification. --------- Signed-off-by: Ping Xie <pingxie@google.com>
This commit is contained in:
parent
906c8e8f90
commit
aaec321213
@ -2211,7 +2211,7 @@ int rewriteStreamObject(rio *r, robj *key, robj *o) {
|
||||
* that is exported by a module and is not handled by Redis itself.
|
||||
* The function returns 0 on error, 1 on success. */
|
||||
int rewriteModuleObject(rio *r, robj *key, robj *o, int dbid) {
|
||||
RedisModuleIO io;
|
||||
ValkeyModuleIO io;
|
||||
moduleValue *mv = o->ptr;
|
||||
moduleType *mt = mv->type;
|
||||
moduleInitIOContext(io,mt,r,key,dbid);
|
||||
|
112
src/call_reply.c
112
src/call_reply.c
@ -73,55 +73,55 @@ static void callReplySetSharedData(CallReply *rep, int type, const char *proto,
|
||||
|
||||
static void callReplyNull(void *ctx, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_NULL, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_NULL, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
}
|
||||
|
||||
static void callReplyNullBulkString(void *ctx, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_NULL, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_NULL, proto, proto_len, 0);
|
||||
}
|
||||
|
||||
static void callReplyNullArray(void *ctx, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_NULL, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_NULL, proto, proto_len, 0);
|
||||
}
|
||||
|
||||
static void callReplyBulkString(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_STRING, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_STRING, proto, proto_len, 0);
|
||||
rep->len = len;
|
||||
rep->val.str = str;
|
||||
}
|
||||
|
||||
static void callReplyError(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_ERROR, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_ERROR, proto, proto_len, 0);
|
||||
rep->len = len;
|
||||
rep->val.str = str;
|
||||
}
|
||||
|
||||
static void callReplySimpleStr(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_STRING, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_STRING, proto, proto_len, 0);
|
||||
rep->len = len;
|
||||
rep->val.str = str;
|
||||
}
|
||||
|
||||
static void callReplyLong(void *ctx, long long val, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_INTEGER, proto, proto_len, 0);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_INTEGER, proto, proto_len, 0);
|
||||
rep->val.ll = val;
|
||||
}
|
||||
|
||||
static void callReplyDouble(void *ctx, double val, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_DOUBLE, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_DOUBLE, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
rep->val.d = val;
|
||||
}
|
||||
|
||||
static void callReplyVerbatimString(void *ctx, const char *format, const char *str, size_t len, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_VERBATIM_STRING, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_VERBATIM_STRING, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
rep->len = len;
|
||||
rep->val.verbatim_str.str = str;
|
||||
rep->val.verbatim_str.format = format;
|
||||
@ -129,14 +129,14 @@ static void callReplyVerbatimString(void *ctx, const char *format, const char *s
|
||||
|
||||
static void callReplyBigNumber(void *ctx, const char *str, size_t len, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_BIG_NUMBER, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_BIG_NUMBER, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
rep->len = len;
|
||||
rep->val.str = str;
|
||||
}
|
||||
|
||||
static void callReplyBool(void *ctx, int val, const char *proto, size_t proto_len) {
|
||||
CallReply *rep = ctx;
|
||||
callReplySetSharedData(rep, REDISMODULE_REPLY_BOOL, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
callReplySetSharedData(rep, VALKEYMODULE_REPLY_BOOL, proto, proto_len, REPLY_FLAG_RESP3);
|
||||
rep->val.ll = val;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ static void callReplyAttribute(ReplyParser *parser, void *ctx, size_t len, const
|
||||
|
||||
/* Continue parsing the attribute reply */
|
||||
rep->attribute->len = len;
|
||||
rep->attribute->type = REDISMODULE_REPLY_ATTRIBUTE;
|
||||
rep->attribute->type = VALKEYMODULE_REPLY_ATTRIBUTE;
|
||||
callReplyParseCollection(parser, rep->attribute, len, proto, 2);
|
||||
rep->attribute->flags |= REPLY_FLAG_PARSED | REPLY_FLAG_RESP3;
|
||||
rep->attribute->private_data = rep->private_data;
|
||||
@ -180,39 +180,39 @@ static void callReplyAttribute(ReplyParser *parser, void *ctx, size_t len, const
|
||||
|
||||
static void callReplyArray(ReplyParser *parser, void *ctx, size_t len, const char *proto) {
|
||||
CallReply *rep = ctx;
|
||||
rep->type = REDISMODULE_REPLY_ARRAY;
|
||||
rep->type = VALKEYMODULE_REPLY_ARRAY;
|
||||
callReplyParseCollection(parser, rep, len, proto, 1);
|
||||
}
|
||||
|
||||
static void callReplySet(ReplyParser *parser, void *ctx, size_t len, const char *proto) {
|
||||
CallReply *rep = ctx;
|
||||
rep->type = REDISMODULE_REPLY_SET;
|
||||
rep->type = VALKEYMODULE_REPLY_SET;
|
||||
callReplyParseCollection(parser, rep, len, proto, 1);
|
||||
rep->flags |= REPLY_FLAG_RESP3;
|
||||
}
|
||||
|
||||
static void callReplyMap(ReplyParser *parser, void *ctx, size_t len, const char *proto) {
|
||||
CallReply *rep = ctx;
|
||||
rep->type = REDISMODULE_REPLY_MAP;
|
||||
rep->type = VALKEYMODULE_REPLY_MAP;
|
||||
callReplyParseCollection(parser, rep, len, proto, 2);
|
||||
rep->flags |= REPLY_FLAG_RESP3;
|
||||
}
|
||||
|
||||
static void callReplyParseError(void *ctx) {
|
||||
CallReply *rep = ctx;
|
||||
rep->type = REDISMODULE_REPLY_UNKNOWN;
|
||||
rep->type = VALKEYMODULE_REPLY_UNKNOWN;
|
||||
}
|
||||
|
||||
/* Recursively free the current call reply and its sub-replies. */
|
||||
static void freeCallReplyInternal(CallReply *rep) {
|
||||
if (rep->type == REDISMODULE_REPLY_ARRAY || rep->type == REDISMODULE_REPLY_SET) {
|
||||
if (rep->type == VALKEYMODULE_REPLY_ARRAY || rep->type == VALKEYMODULE_REPLY_SET) {
|
||||
for (size_t i = 0 ; i < rep->len ; ++i) {
|
||||
freeCallReplyInternal(rep->val.array + i);
|
||||
}
|
||||
zfree(rep->val.array);
|
||||
}
|
||||
|
||||
if (rep->type == REDISMODULE_REPLY_MAP || rep->type == REDISMODULE_REPLY_ATTRIBUTE) {
|
||||
if (rep->type == VALKEYMODULE_REPLY_MAP || rep->type == VALKEYMODULE_REPLY_ATTRIBUTE) {
|
||||
for (size_t i = 0 ; i < rep->len ; ++i) {
|
||||
freeCallReplyInternal(rep->val.array + i * 2);
|
||||
freeCallReplyInternal(rep->val.array + i * 2 + 1);
|
||||
@ -234,7 +234,7 @@ void freeCallReply(CallReply *rep) {
|
||||
return;
|
||||
}
|
||||
if (rep->flags & REPLY_FLAG_PARSED) {
|
||||
if (rep->type == REDISMODULE_REPLY_PROMISE) {
|
||||
if (rep->type == VALKEYMODULE_REPLY_PROMISE) {
|
||||
zfree(rep);
|
||||
return;
|
||||
}
|
||||
@ -248,7 +248,7 @@ void freeCallReply(CallReply *rep) {
|
||||
|
||||
CallReply *callReplyCreatePromise(void *private_data) {
|
||||
CallReply *res = zmalloc(sizeof(*res));
|
||||
res->type = REDISMODULE_REPLY_PROMISE;
|
||||
res->type = VALKEYMODULE_REPLY_PROMISE;
|
||||
/* Mark the reply as parsed so there will be not attempt to parse
|
||||
* it when calling reply API such as freeCallReply.
|
||||
* Also mark the reply as root so freeCallReply will not ignore it. */
|
||||
@ -289,16 +289,16 @@ static void callReplyParse(CallReply *rep) {
|
||||
rep->flags |= REPLY_FLAG_PARSED;
|
||||
}
|
||||
|
||||
/* Return the call reply type (REDISMODULE_REPLY_...). */
|
||||
/* Return the call reply type (VALKEYMODULE_REPLY_...). */
|
||||
int callReplyType(CallReply *rep) {
|
||||
if (!rep) return REDISMODULE_REPLY_UNKNOWN;
|
||||
if (!rep) return VALKEYMODULE_REPLY_UNKNOWN;
|
||||
callReplyParse(rep);
|
||||
return rep->type;
|
||||
}
|
||||
|
||||
/* Return reply string as buffer and len. Applicable to:
|
||||
* - REDISMODULE_REPLY_STRING
|
||||
* - REDISMODULE_REPLY_ERROR
|
||||
* - VALKEYMODULE_REPLY_STRING
|
||||
* - VALKEYMODULE_REPLY_ERROR
|
||||
*
|
||||
* The return value is borrowed from CallReply, so it must not be freed
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
@ -308,56 +308,56 @@ int callReplyType(CallReply *rep) {
|
||||
*/
|
||||
const char *callReplyGetString(CallReply *rep, size_t *len) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_STRING &&
|
||||
rep->type != REDISMODULE_REPLY_ERROR) return NULL;
|
||||
if (rep->type != VALKEYMODULE_REPLY_STRING &&
|
||||
rep->type != VALKEYMODULE_REPLY_ERROR) return NULL;
|
||||
if (len) *len = rep->len;
|
||||
return rep->val.str;
|
||||
}
|
||||
|
||||
/* Return a long long reply value. Applicable to:
|
||||
* - REDISMODULE_REPLY_INTEGER
|
||||
* - VALKEYMODULE_REPLY_INTEGER
|
||||
*/
|
||||
long long callReplyGetLongLong(CallReply *rep) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_INTEGER) return LLONG_MIN;
|
||||
if (rep->type != VALKEYMODULE_REPLY_INTEGER) return LLONG_MIN;
|
||||
return rep->val.ll;
|
||||
}
|
||||
|
||||
/* Return a double reply value. Applicable to:
|
||||
* - REDISMODULE_REPLY_DOUBLE
|
||||
* - VALKEYMODULE_REPLY_DOUBLE
|
||||
*/
|
||||
double callReplyGetDouble(CallReply *rep) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_DOUBLE) return LLONG_MIN;
|
||||
if (rep->type != VALKEYMODULE_REPLY_DOUBLE) return LLONG_MIN;
|
||||
return rep->val.d;
|
||||
}
|
||||
|
||||
/* Return a reply Boolean value. Applicable to:
|
||||
* - REDISMODULE_REPLY_BOOL
|
||||
* - VALKEYMODULE_REPLY_BOOL
|
||||
*/
|
||||
int callReplyGetBool(CallReply *rep) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_BOOL) return INT_MIN;
|
||||
if (rep->type != VALKEYMODULE_REPLY_BOOL) return INT_MIN;
|
||||
return rep->val.ll;
|
||||
}
|
||||
|
||||
/* Return reply length. Applicable to:
|
||||
* - REDISMODULE_REPLY_STRING
|
||||
* - REDISMODULE_REPLY_ERROR
|
||||
* - REDISMODULE_REPLY_ARRAY
|
||||
* - REDISMODULE_REPLY_SET
|
||||
* - REDISMODULE_REPLY_MAP
|
||||
* - REDISMODULE_REPLY_ATTRIBUTE
|
||||
* - VALKEYMODULE_REPLY_STRING
|
||||
* - VALKEYMODULE_REPLY_ERROR
|
||||
* - VALKEYMODULE_REPLY_ARRAY
|
||||
* - VALKEYMODULE_REPLY_SET
|
||||
* - VALKEYMODULE_REPLY_MAP
|
||||
* - VALKEYMODULE_REPLY_ATTRIBUTE
|
||||
*/
|
||||
size_t callReplyGetLen(CallReply *rep) {
|
||||
callReplyParse(rep);
|
||||
switch(rep->type) {
|
||||
case REDISMODULE_REPLY_STRING:
|
||||
case REDISMODULE_REPLY_ERROR:
|
||||
case REDISMODULE_REPLY_ARRAY:
|
||||
case REDISMODULE_REPLY_SET:
|
||||
case REDISMODULE_REPLY_MAP:
|
||||
case REDISMODULE_REPLY_ATTRIBUTE:
|
||||
case VALKEYMODULE_REPLY_STRING:
|
||||
case VALKEYMODULE_REPLY_ERROR:
|
||||
case VALKEYMODULE_REPLY_ARRAY:
|
||||
case VALKEYMODULE_REPLY_SET:
|
||||
case VALKEYMODULE_REPLY_MAP:
|
||||
case VALKEYMODULE_REPLY_ATTRIBUTE:
|
||||
return rep->len;
|
||||
default:
|
||||
return 0;
|
||||
@ -370,26 +370,26 @@ static CallReply *callReplyGetCollectionElement(CallReply *rep, size_t idx, int
|
||||
}
|
||||
|
||||
/* Return a reply array element at a given index. Applicable to:
|
||||
* - REDISMODULE_REPLY_ARRAY
|
||||
* - VALKEYMODULE_REPLY_ARRAY
|
||||
*
|
||||
* The return value is borrowed from CallReply, so it must not be freed
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
*/
|
||||
CallReply *callReplyGetArrayElement(CallReply *rep, size_t idx) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_ARRAY) return NULL;
|
||||
if (rep->type != VALKEYMODULE_REPLY_ARRAY) return NULL;
|
||||
return callReplyGetCollectionElement(rep, idx, 1);
|
||||
}
|
||||
|
||||
/* Return a reply set element at a given index. Applicable to:
|
||||
* - REDISMODULE_REPLY_SET
|
||||
* - VALKEYMODULE_REPLY_SET
|
||||
*
|
||||
* The return value is borrowed from CallReply, so it must not be freed
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
*/
|
||||
CallReply *callReplyGetSetElement(CallReply *rep, size_t idx) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_SET) return NULL;
|
||||
if (rep->type != VALKEYMODULE_REPLY_SET) return NULL;
|
||||
return callReplyGetCollectionElement(rep, idx, 1);
|
||||
}
|
||||
|
||||
@ -403,7 +403,7 @@ static int callReplyGetMapElementInternal(CallReply *rep, size_t idx, CallReply
|
||||
}
|
||||
|
||||
/* Retrieve a map reply key and value at a given index. Applicable to:
|
||||
* - REDISMODULE_REPLY_MAP
|
||||
* - VALKEYMODULE_REPLY_MAP
|
||||
*
|
||||
* The key and value are returned by reference through key and val,
|
||||
* which may also be NULL if not needed.
|
||||
@ -415,7 +415,7 @@ static int callReplyGetMapElementInternal(CallReply *rep, size_t idx, CallReply
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
*/
|
||||
int callReplyGetMapElement(CallReply *rep, size_t idx, CallReply **key, CallReply **val) {
|
||||
return callReplyGetMapElementInternal(rep, idx, key, val, REDISMODULE_REPLY_MAP);
|
||||
return callReplyGetMapElementInternal(rep, idx, key, val, VALKEYMODULE_REPLY_MAP);
|
||||
}
|
||||
|
||||
/* Return reply attribute, or NULL if it does not exist. Applicable to all replies.
|
||||
@ -428,7 +428,7 @@ CallReply *callReplyGetAttribute(CallReply *rep) {
|
||||
}
|
||||
|
||||
/* Retrieve attribute reply key and value at a given index. Applicable to:
|
||||
* - REDISMODULE_REPLY_ATTRIBUTE
|
||||
* - VALKEYMODULE_REPLY_ATTRIBUTE
|
||||
*
|
||||
* The key and value are returned by reference through key and val,
|
||||
* which may also be NULL if not needed.
|
||||
@ -440,11 +440,11 @@ CallReply *callReplyGetAttribute(CallReply *rep) {
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
*/
|
||||
int callReplyGetAttributeElement(CallReply *rep, size_t idx, CallReply **key, CallReply **val) {
|
||||
return callReplyGetMapElementInternal(rep, idx, key, val, REDISMODULE_REPLY_MAP);
|
||||
return callReplyGetMapElementInternal(rep, idx, key, val, VALKEYMODULE_REPLY_MAP);
|
||||
}
|
||||
|
||||
/* Return a big number reply value. Applicable to:
|
||||
* - REDISMODULE_REPLY_BIG_NUMBER
|
||||
* - VALKEYMODULE_REPLY_BIG_NUMBER
|
||||
*
|
||||
* The returned values are borrowed from CallReply, so they must not be freed
|
||||
* explicitly or used after CallReply itself is freed.
|
||||
@ -457,13 +457,13 @@ int callReplyGetAttributeElement(CallReply *rep, size_t idx, CallReply **key, Ca
|
||||
*/
|
||||
const char *callReplyGetBigNumber(CallReply *rep, size_t *len) {
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_BIG_NUMBER) return NULL;
|
||||
if (rep->type != VALKEYMODULE_REPLY_BIG_NUMBER) return NULL;
|
||||
*len = rep->len;
|
||||
return rep->val.str;
|
||||
}
|
||||
|
||||
/* Return a verbatim string reply value. Applicable to:
|
||||
* - REDISMODULE_REPLY_VERBATIM_STRING
|
||||
* - VALKEYMODULE_REPLY_VERBATIM_STRING
|
||||
*
|
||||
* If format is non-NULL, the verbatim reply format is also returned by value.
|
||||
*
|
||||
@ -478,7 +478,7 @@ const char *callReplyGetBigNumber(CallReply *rep, size_t *len) {
|
||||
*/
|
||||
const char *callReplyGetVerbatim(CallReply *rep, size_t *len, const char **format){
|
||||
callReplyParse(rep);
|
||||
if (rep->type != REDISMODULE_REPLY_VERBATIM_STRING) return NULL;
|
||||
if (rep->type != VALKEYMODULE_REPLY_VERBATIM_STRING) return NULL;
|
||||
*len = rep->len;
|
||||
if (format) *format = rep->val.verbatim_str.format;
|
||||
return rep->val.verbatim_str.str;
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "resp_parser.h"
|
||||
|
||||
typedef struct CallReply CallReply;
|
||||
typedef void (*RedisModuleOnUnblocked)(void *ctx, CallReply *reply, void *private_data);
|
||||
typedef void (*ValkeyModuleOnUnblocked)(void *ctx, CallReply *reply, void *private_data);
|
||||
|
||||
CallReply *callReplyCreate(sds reply, list *deferred_error_list, void *private_data);
|
||||
CallReply *callReplyCreateError(sds reply, void *private_data);
|
||||
|
@ -934,8 +934,8 @@ void configSetCommand(client *c) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
RedisModuleConfigChangeV1 cc = {.num_changes = config_count, .config_names = config_names};
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_CONFIG, REDISMODULE_SUBEVENT_CONFIG_CHANGE, &cc);
|
||||
ValkeyModuleConfigChangeV1 cc = {.num_changes = config_count, .config_names = config_names};
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_CONFIG, VALKEYMODULE_SUBEVENT_CONFIG_CHANGE, &cc);
|
||||
addReply(c,shared.ok);
|
||||
goto end;
|
||||
|
||||
@ -1588,7 +1588,7 @@ void rewriteConfigLoadmoduleOption(struct rewriteConfigState *state) {
|
||||
dictIterator *di = dictGetIterator(modules);
|
||||
dictEntry *de;
|
||||
while ((de = dictNext(di)) != NULL) {
|
||||
struct RedisModule *module = dictGetVal(de);
|
||||
struct ValkeyModule *module = dictGetVal(de);
|
||||
line = sdsnew("loadmodule ");
|
||||
line = sdscatsds(line, module->loadmod->path);
|
||||
for (int i = 0; i < module->loadmod->argc; i++) {
|
||||
|
18
src/db.c
18
src/db.c
@ -524,7 +524,7 @@ long long emptyDbStructure(serverDb *dbarray, int dbnum, int async,
|
||||
long long emptyData(int dbnum, int flags, void(callback)(dict*)) {
|
||||
int async = (flags & EMPTYDB_ASYNC);
|
||||
int with_functions = !(flags & EMPTYDB_NOFUNCTIONS);
|
||||
RedisModuleFlushInfoV1 fi = {REDISMODULE_FLUSHINFO_VERSION,!async,dbnum};
|
||||
ValkeyModuleFlushInfoV1 fi = {VALKEYMODULE_FLUSHINFO_VERSION,!async,dbnum};
|
||||
long long removed = 0;
|
||||
|
||||
if (dbnum < -1 || dbnum >= server.dbnum) {
|
||||
@ -533,8 +533,8 @@ long long emptyData(int dbnum, int flags, void(callback)(dict*)) {
|
||||
}
|
||||
|
||||
/* Fire the flushdb modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
||||
REDISMODULE_SUBEVENT_FLUSHDB_START,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_FLUSHDB,
|
||||
VALKEYMODULE_SUBEVENT_FLUSHDB_START,
|
||||
&fi);
|
||||
|
||||
/* Make sure the WATCHed keys are affected by the FLUSH* commands.
|
||||
@ -554,8 +554,8 @@ long long emptyData(int dbnum, int flags, void(callback)(dict*)) {
|
||||
|
||||
/* Also fire the end event. Note that this event will fire almost
|
||||
* immediately after the start event if the flush is asynchronous. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_FLUSHDB,
|
||||
REDISMODULE_SUBEVENT_FLUSHDB_END,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_FLUSHDB,
|
||||
VALKEYMODULE_SUBEVENT_FLUSHDB_END,
|
||||
&fi);
|
||||
|
||||
return removed;
|
||||
@ -865,7 +865,7 @@ int objectTypeCompare(robj *o, long long target) {
|
||||
return 1;
|
||||
}
|
||||
/* module type compare */
|
||||
long long mt = (long long)REDISMODULE_TYPE_SIGN(((moduleValue *)o->ptr)->type->id);
|
||||
long long mt = (long long)VALKEYMODULE_TYPE_SIGN(((moduleValue *)o->ptr)->type->id);
|
||||
if (target != -mt)
|
||||
return 0;
|
||||
else
|
||||
@ -951,7 +951,7 @@ long long getObjectTypeByName(char *name) {
|
||||
}
|
||||
|
||||
moduleType *mt = moduleTypeLookupModuleByNameIgnoreCase(name);
|
||||
if (mt != NULL) return -(REDISMODULE_TYPE_SIGN(mt->id));
|
||||
if (mt != NULL) return -(VALKEYMODULE_TYPE_SIGN(mt->id));
|
||||
|
||||
return LLONG_MAX;
|
||||
}
|
||||
@ -1680,8 +1680,8 @@ void swapdbCommand(client *c) {
|
||||
addReplyError(c,"DB index is out of range");
|
||||
return;
|
||||
} else {
|
||||
RedisModuleSwapDbInfo si = {REDISMODULE_SWAPDBINFO_VERSION,id1,id2};
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_SWAPDB,0,&si);
|
||||
ValkeyModuleSwapDbInfo si = {VALKEYMODULE_SWAPDBINFO_VERSION,id1,id2};
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_SWAPDB,0,&si);
|
||||
server.dirty++;
|
||||
addReply(c,shared.ok);
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ void xorObjectDigest(serverDb *db, robj *keyobj, unsigned char *digest, robj *o)
|
||||
}
|
||||
streamIteratorStop(&si);
|
||||
} else if (o->type == OBJ_MODULE) {
|
||||
RedisModuleDigest md = {{0},{0},keyobj,db->id};
|
||||
ValkeyModuleDigest md = {{0},{0},keyobj,db->id};
|
||||
moduleValue *mv = o->ptr;
|
||||
moduleType *mt = mv->type;
|
||||
moduleInitDigestContext(md);
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
#include "server.h"
|
||||
#include "script.h"
|
||||
#include "redismodule.h"
|
||||
#include "valkeymodule.h"
|
||||
|
||||
typedef struct functionLibInfo functionLibInfo;
|
||||
|
||||
|
5650
src/module.c
5650
src/module.c
File diff suppressed because it is too large
Load Diff
@ -25,42 +25,42 @@ all: helloworld.so hellotype.so helloblock.so hellocluster.so hellotimer.so hell
|
||||
.c.xo:
|
||||
$(CC) -I. $(CFLAGS) $(SHOBJ_CFLAGS) -fPIC -c $< -o $@
|
||||
|
||||
helloworld.xo: ../redismodule.h
|
||||
helloworld.xo: ../valkeymodule.h
|
||||
|
||||
helloworld.so: helloworld.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
hellotype.xo: ../redismodule.h
|
||||
hellotype.xo: ../valkeymodule.h
|
||||
|
||||
hellotype.so: hellotype.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
helloblock.xo: ../redismodule.h
|
||||
helloblock.xo: ../valkeymodule.h
|
||||
|
||||
helloblock.so: helloblock.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lpthread -lc
|
||||
|
||||
hellocluster.xo: ../redismodule.h
|
||||
hellocluster.xo: ../valkeymodule.h
|
||||
|
||||
hellocluster.so: hellocluster.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
hellotimer.xo: ../redismodule.h
|
||||
hellotimer.xo: ../valkeymodule.h
|
||||
|
||||
hellotimer.so: hellotimer.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
hellodict.xo: ../redismodule.h
|
||||
hellodict.xo: ../valkeymodule.h
|
||||
|
||||
hellodict.so: hellodict.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
hellohook.xo: ../redismodule.h
|
||||
hellohook.xo: ../valkeymodule.h
|
||||
|
||||
hellohook.so: hellohook.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
||||
helloacl.xo: ../redismodule.h
|
||||
helloacl.xo: ../valkeymodule.h
|
||||
|
||||
helloacl.so: helloacl.xo
|
||||
$(LD) -o $@ $^ $(SHOBJ_LDFLAGS) $(LIBS) -lc
|
||||
|
@ -31,7 +31,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -42,8 +42,8 @@ static uint64_t global_auth_client_id = 0;
|
||||
/* HELLOACL.REVOKE
|
||||
* Synchronously revoke access from a user. */
|
||||
int RevokeCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (global_auth_client_id) {
|
||||
RedisModule_DeauthenticateAndCloseClient(ctx, global_auth_client_id);
|
||||
@ -56,8 +56,8 @@ int RevokeCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
|
||||
/* HELLOACL.RESET
|
||||
* Synchronously delete and re-create a module user. */
|
||||
int ResetCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
RedisModule_FreeModuleUser(global);
|
||||
global = RedisModule_CreateModuleUser("global");
|
||||
@ -71,16 +71,16 @@ int ResetCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
/* Callback handler for user changes, use this to notify a module of
|
||||
* changes to users authenticated by the module */
|
||||
void HelloACL_UserChanged(uint64_t client_id, void *privdata) {
|
||||
REDISMODULE_NOT_USED(privdata);
|
||||
REDISMODULE_NOT_USED(client_id);
|
||||
VALKEYMODULE_NOT_USED(privdata);
|
||||
VALKEYMODULE_NOT_USED(client_id);
|
||||
global_auth_client_id = 0;
|
||||
}
|
||||
|
||||
/* HELLOACL.AUTHGLOBAL
|
||||
* Synchronously assigns a module user to the current context. */
|
||||
int AuthGlobalCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (global_auth_client_id) {
|
||||
return RedisModule_ReplyWithError(ctx, "Global user currently used");
|
||||
@ -95,15 +95,15 @@ int AuthGlobalCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv
|
||||
|
||||
/* Reply callback for auth command HELLOACL.AUTHASYNC */
|
||||
int HelloACL_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
size_t length;
|
||||
|
||||
RedisModuleString *user_string = RedisModule_GetBlockedClientPrivateData(ctx);
|
||||
const char *name = RedisModule_StringPtrLen(user_string, &length);
|
||||
|
||||
if (RedisModule_AuthenticateClientWithACLUser(ctx, name, length, NULL, NULL, NULL) ==
|
||||
REDISMODULE_ERR) {
|
||||
VALKEYMODULE_ERR) {
|
||||
return RedisModule_ReplyWithError(ctx, "Invalid Username or password");
|
||||
}
|
||||
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
||||
@ -111,14 +111,14 @@ int HelloACL_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
|
||||
/* Timeout callback for auth command HELLOACL.AUTHASYNC */
|
||||
int HelloACL_Timeout(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
return RedisModule_ReplyWithSimpleString(ctx, "Request timedout");
|
||||
}
|
||||
|
||||
/* Private data frees data for HELLOACL.AUTHASYNC command. */
|
||||
void HelloACL_FreeData(RedisModuleCtx *ctx, void *privdata) {
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
RedisModule_FreeString(NULL, privdata);
|
||||
}
|
||||
|
||||
@ -151,33 +151,33 @@ int AuthAsyncCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
return RedisModule_ReplyWithError(ctx, "-ERR Can't start thread");
|
||||
}
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"helloacl",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"helloacl",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"helloacl.reset",
|
||||
ResetCommand_RedisCommand,"",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
ResetCommand_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"helloacl.revoke",
|
||||
RevokeCommand_RedisCommand,"",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
RevokeCommand_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"helloacl.authglobal",
|
||||
AuthGlobalCommand_RedisCommand,"no-auth",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
AuthGlobalCommand_RedisCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"helloacl.authasync",
|
||||
AuthAsyncCommand_RedisCommand,"no-auth",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
AuthAsyncCommand_RedisCommand,"no-auth",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
global = RedisModule_CreateModuleUser("global");
|
||||
RedisModule_SetModuleUserACL(global, "allcommands");
|
||||
@ -186,5 +186,5 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
|
||||
global_auth_client_id = 0;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
@ -39,22 +39,22 @@
|
||||
|
||||
/* Reply callback for blocking command HELLO.BLOCK */
|
||||
int HelloBlock_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
int *myint = RedisModule_GetBlockedClientPrivateData(ctx);
|
||||
return RedisModule_ReplyWithLongLong(ctx,*myint);
|
||||
}
|
||||
|
||||
/* Timeout callback for blocking command HELLO.BLOCK */
|
||||
int HelloBlock_Timeout(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
return RedisModule_ReplyWithSimpleString(ctx,"Request timedout");
|
||||
}
|
||||
|
||||
/* Private data freeing callback for HELLO.BLOCK command. */
|
||||
void HelloBlock_FreeData(RedisModuleCtx *ctx, void *privdata) {
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
RedisModule_Free(privdata);
|
||||
}
|
||||
|
||||
@ -98,11 +98,11 @@ int HelloBlock_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
|
||||
long long delay;
|
||||
long long timeout;
|
||||
|
||||
if (RedisModule_StringToLongLong(argv[1],&delay) != REDISMODULE_OK) {
|
||||
if (RedisModule_StringToLongLong(argv[1],&delay) != VALKEYMODULE_OK) {
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid count");
|
||||
}
|
||||
|
||||
if (RedisModule_StringToLongLong(argv[2],&timeout) != REDISMODULE_OK) {
|
||||
if (RedisModule_StringToLongLong(argv[2],&timeout) != VALKEYMODULE_OK) {
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid count");
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ int HelloBlock_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
|
||||
RedisModule_AbortBlock(bc);
|
||||
return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread");
|
||||
}
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* The thread entry point that actually executes the blocking part
|
||||
@ -141,7 +141,7 @@ void *HelloKeys_ThreadMain(void *arg) {
|
||||
long long cursor = 0;
|
||||
size_t replylen = 0;
|
||||
|
||||
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_LEN);
|
||||
RedisModule_ReplyWithArray(ctx,VALKEYMODULE_POSTPONED_LEN);
|
||||
do {
|
||||
RedisModule_ThreadSafeContextLock(ctx);
|
||||
RedisModuleCallReply *reply = RedisModule_Call(ctx,
|
||||
@ -178,7 +178,7 @@ void *HelloKeys_ThreadMain(void *arg) {
|
||||
* that were in the database from the start to the end are guaranteed to be
|
||||
* there. */
|
||||
int HelloKeys_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
if (argc != 1) return RedisModule_WrongArity(ctx);
|
||||
|
||||
pthread_t tid;
|
||||
@ -195,24 +195,24 @@ int HelloKeys_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int ar
|
||||
RedisModule_AbortBlock(bc);
|
||||
return RedisModule_ReplyWithError(ctx,"-ERR Can't start thread");
|
||||
}
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"helloblock",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"helloblock",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.block",
|
||||
HelloBlock_RedisCommand,"",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloBlock_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
if (RedisModule_CreateCommand(ctx,"hello.keys",
|
||||
HelloKeys_RedisCommand,"",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloKeys_RedisCommand,"",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -41,8 +41,8 @@
|
||||
|
||||
/* HELLOCLUSTER.PINGALL */
|
||||
int PingallCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
RedisModule_SendClusterMessage(ctx,NULL,MSGTYPE_PING,"Hey",3);
|
||||
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
||||
@ -50,8 +50,8 @@ int PingallCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
|
||||
/* HELLOCLUSTER.LIST */
|
||||
int ListCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
size_t numnodes;
|
||||
char **ids = RedisModule_GetClusterNodesList(ctx,&numnodes);
|
||||
@ -64,17 +64,17 @@ int ListCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
int port;
|
||||
RedisModule_GetClusterNodeInfo(ctx,ids[j],NULL,NULL,&port,NULL);
|
||||
RedisModule_ReplyWithArray(ctx,2);
|
||||
RedisModule_ReplyWithStringBuffer(ctx,ids[j],REDISMODULE_NODE_ID_LEN);
|
||||
RedisModule_ReplyWithStringBuffer(ctx,ids[j],VALKEYMODULE_NODE_ID_LEN);
|
||||
RedisModule_ReplyWithLongLong(ctx,port);
|
||||
}
|
||||
RedisModule_FreeClusterNodesList(ids);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* Callback for message MSGTYPE_PING */
|
||||
void PingReceiver(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len) {
|
||||
RedisModule_Log(ctx,"notice","PING (type %d) RECEIVED from %.*s: '%.*s'",
|
||||
type,REDISMODULE_NODE_ID_LEN,sender_id,(int)len, payload);
|
||||
type,VALKEYMODULE_NODE_ID_LEN,sender_id,(int)len, payload);
|
||||
RedisModule_SendClusterMessage(ctx,NULL,MSGTYPE_PONG,"Ohi!",4);
|
||||
RedisModuleCallReply *reply = RedisModule_Call(ctx, "INCR", "c", "pings_received");
|
||||
RedisModule_FreeCallReply(reply);
|
||||
@ -83,25 +83,25 @@ void PingReceiver(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, cons
|
||||
/* Callback for message MSGTYPE_PONG. */
|
||||
void PongReceiver(RedisModuleCtx *ctx, const char *sender_id, uint8_t type, const unsigned char *payload, uint32_t len) {
|
||||
RedisModule_Log(ctx,"notice","PONG (type %d) RECEIVED from %.*s: '%.*s'",
|
||||
type,REDISMODULE_NODE_ID_LEN,sender_id,(int)len, payload);
|
||||
type,VALKEYMODULE_NODE_ID_LEN,sender_id,(int)len, payload);
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"hellocluster",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"hellocluster",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellocluster.pingall",
|
||||
PingallCommand_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
PingallCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellocluster.list",
|
||||
ListCommand_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
ListCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
/* Disable Redis Cluster sharding and redirections. This way every node
|
||||
* will be able to access every possible key, regardless of the hash slot.
|
||||
@ -109,10 +109,10 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
* variable. Normally you do that in order for the distributed system
|
||||
* you create as a module to have total freedom in the keyspace
|
||||
* manipulation. */
|
||||
RedisModule_SetClusterFlags(ctx,REDISMODULE_CLUSTER_FLAG_NO_REDIRECTION);
|
||||
RedisModule_SetClusterFlags(ctx,VALKEYMODULE_CLUSTER_FLAG_NO_REDIRECTION);
|
||||
|
||||
/* Register our handlers for different message types. */
|
||||
RedisModule_RegisterClusterMessageReceiver(ctx,MSGTYPE_PING,PingReceiver);
|
||||
RedisModule_RegisterClusterMessageReceiver(ctx,MSGTYPE_PONG,PongReceiver);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -76,7 +76,7 @@ int cmd_KEYRANGE(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
|
||||
/* Parse the count argument. */
|
||||
long long count;
|
||||
if (RedisModule_StringToLongLong(argv[3],&count) != REDISMODULE_OK) {
|
||||
if (RedisModule_StringToLongLong(argv[3],&count) != VALKEYMODULE_OK) {
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid count");
|
||||
}
|
||||
|
||||
@ -88,10 +88,10 @@ int cmd_KEYRANGE(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
char *key;
|
||||
size_t keylen;
|
||||
long long replylen = 0; /* Keep track of the emitted array len. */
|
||||
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_LEN);
|
||||
RedisModule_ReplyWithArray(ctx,VALKEYMODULE_POSTPONED_LEN);
|
||||
while((key = RedisModule_DictNextC(iter,&keylen,NULL)) != NULL) {
|
||||
if (replylen >= count) break;
|
||||
if (RedisModule_DictCompare(iter,"<=",argv[2]) == REDISMODULE_ERR)
|
||||
if (RedisModule_DictCompare(iter,"<=",argv[2]) == VALKEYMODULE_ERR)
|
||||
break;
|
||||
RedisModule_ReplyWithStringBuffer(ctx,key,keylen);
|
||||
replylen++;
|
||||
@ -100,32 +100,32 @@ int cmd_KEYRANGE(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
|
||||
/* Cleanup. */
|
||||
RedisModule_DictIteratorStop(iter);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"hellodict",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"hellodict",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellodict.set",
|
||||
cmd_SET,"write deny-oom",1,1,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
cmd_SET,"write deny-oom",1,1,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellodict.get",
|
||||
cmd_GET,"readonly",1,1,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
cmd_GET,"readonly",1,1,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellodict.keyrange",
|
||||
cmd_KEYRANGE,"readonly",1,1,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
cmd_KEYRANGE,"readonly",1,1,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
/* Create our global dictionary. Here we'll set our keys and values. */
|
||||
Keyspace = RedisModule_CreateDict(NULL);
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -39,23 +39,23 @@
|
||||
/* Client state change callback. */
|
||||
void clientChangeCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data)
|
||||
{
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
REDISMODULE_NOT_USED(e);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(e);
|
||||
|
||||
RedisModuleClientInfo *ci = data;
|
||||
printf("Client %s event for client #%llu %s:%d\n",
|
||||
(sub == REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED) ?
|
||||
(sub == VALKEYMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED) ?
|
||||
"connection" : "disconnection",
|
||||
(unsigned long long)ci->id,ci->addr,ci->port);
|
||||
}
|
||||
|
||||
void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void *data)
|
||||
{
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
REDISMODULE_NOT_USED(e);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(e);
|
||||
|
||||
RedisModuleFlushInfo *fi = data;
|
||||
if (sub == REDISMODULE_SUBEVENT_FLUSHDB_START) {
|
||||
if (sub == VALKEYMODULE_SUBEVENT_FLUSHDB_START) {
|
||||
if (fi->dbnum != -1) {
|
||||
RedisModuleCallReply *reply;
|
||||
reply = RedisModule_Call(ctx,"DBSIZE","");
|
||||
@ -78,15 +78,15 @@ void flushdbCallback(RedisModuleCtx *ctx, RedisModuleEvent e, uint64_t sub, void
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"hellohook",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"hellohook",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
RedisModule_SubscribeToServerEvent(ctx,
|
||||
RedisModuleEvent_ClientChange, clientChangeCallback);
|
||||
RedisModule_SubscribeToServerEvent(ctx,
|
||||
RedisModuleEvent_FlushDB, flushdbCallback);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -38,22 +38,22 @@
|
||||
|
||||
/* Timer callback. */
|
||||
void timerHandler(RedisModuleCtx *ctx, void *data) {
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
printf("Fired %s!\n", (char *)data);
|
||||
RedisModule_Free(data);
|
||||
}
|
||||
|
||||
/* HELLOTIMER.TIMER*/
|
||||
int TimerCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
for (int j = 0; j < 10; j++) {
|
||||
int delay = rand() % 5000;
|
||||
char *buf = RedisModule_Alloc(256);
|
||||
snprintf(buf,256,"After %d", delay);
|
||||
RedisModuleTimerID tid = RedisModule_CreateTimer(ctx,delay,timerHandler,buf);
|
||||
REDISMODULE_NOT_USED(tid);
|
||||
VALKEYMODULE_NOT_USED(tid);
|
||||
}
|
||||
return RedisModule_ReplyWithSimpleString(ctx, "OK");
|
||||
}
|
||||
@ -61,15 +61,15 @@ int TimerCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"hellotimer",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"hellotimer",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellotimer.timer",
|
||||
TimerCommand_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
TimerCommand_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -105,22 +105,22 @@ int HelloTypeInsert_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
|
||||
if (argc != 3) return RedisModule_WrongArity(ctx);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_EMPTY &&
|
||||
if (type != VALKEYMODULE_KEYTYPE_EMPTY &&
|
||||
RedisModule_ModuleTypeGetType(key) != HelloType)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
long long value;
|
||||
if ((RedisModule_StringToLongLong(argv[2],&value) != REDISMODULE_OK)) {
|
||||
if ((RedisModule_StringToLongLong(argv[2],&value) != VALKEYMODULE_OK)) {
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid value: must be a signed 64 bit integer");
|
||||
}
|
||||
|
||||
/* Create an empty value object if the key is currently empty. */
|
||||
struct HelloTypeObject *hto;
|
||||
if (type == REDISMODULE_KEYTYPE_EMPTY) {
|
||||
if (type == VALKEYMODULE_KEYTYPE_EMPTY) {
|
||||
hto = createHelloTypeObject();
|
||||
RedisModule_ModuleTypeSetValue(key,HelloType,hto);
|
||||
} else {
|
||||
@ -133,7 +133,7 @@ int HelloTypeInsert_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
|
||||
RedisModule_ReplyWithLongLong(ctx,hto->len);
|
||||
RedisModule_ReplicateVerbatim(ctx);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLOTYPE.RANGE key first count */
|
||||
@ -142,17 +142,17 @@ int HelloTypeRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
|
||||
if (argc != 4) return RedisModule_WrongArity(ctx);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_EMPTY &&
|
||||
if (type != VALKEYMODULE_KEYTYPE_EMPTY &&
|
||||
RedisModule_ModuleTypeGetType(key) != HelloType)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
long long first, count;
|
||||
if (RedisModule_StringToLongLong(argv[2],&first) != REDISMODULE_OK ||
|
||||
RedisModule_StringToLongLong(argv[3],&count) != REDISMODULE_OK ||
|
||||
if (RedisModule_StringToLongLong(argv[2],&first) != VALKEYMODULE_OK ||
|
||||
RedisModule_StringToLongLong(argv[3],&count) != VALKEYMODULE_OK ||
|
||||
first < 0 || count < 0)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,
|
||||
@ -161,7 +161,7 @@ int HelloTypeRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
|
||||
struct HelloTypeObject *hto = RedisModule_ModuleTypeGetValue(key);
|
||||
struct HelloTypeNode *node = hto ? hto->head : NULL;
|
||||
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_LEN);
|
||||
RedisModule_ReplyWithArray(ctx,VALKEYMODULE_POSTPONED_LEN);
|
||||
long long arraylen = 0;
|
||||
while(node && count--) {
|
||||
RedisModule_ReplyWithLongLong(ctx,node->value);
|
||||
@ -169,7 +169,7 @@ int HelloTypeRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
node = node->next;
|
||||
}
|
||||
RedisModule_ReplySetArrayLength(ctx,arraylen);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLOTYPE.LEN key */
|
||||
@ -178,17 +178,17 @@ int HelloTypeLen_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
|
||||
if (argc != 2) return RedisModule_WrongArity(ctx);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_EMPTY &&
|
||||
if (type != VALKEYMODULE_KEYTYPE_EMPTY &&
|
||||
RedisModule_ModuleTypeGetType(key) != HelloType)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
struct HelloTypeObject *hto = RedisModule_ModuleTypeGetValue(key);
|
||||
RedisModule_ReplyWithLongLong(ctx,hto ? hto->len : 0);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* ====================== Example of a blocking command ==================== */
|
||||
@ -197,17 +197,17 @@ int HelloTypeLen_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
* called when the key we blocked for is ready: we need to check if we
|
||||
* can really serve the client, and reply OK or ERR accordingly. */
|
||||
int HelloBlock_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
RedisModuleString *keyname = RedisModule_GetBlockedClientReadyKey(ctx);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,keyname,REDISMODULE_READ);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,keyname,VALKEYMODULE_READ);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_MODULE ||
|
||||
if (type != VALKEYMODULE_KEYTYPE_MODULE ||
|
||||
RedisModule_ModuleTypeGetType(key) != HelloType)
|
||||
{
|
||||
RedisModule_CloseKey(key);
|
||||
return REDISMODULE_ERR;
|
||||
return VALKEYMODULE_ERR;
|
||||
}
|
||||
|
||||
/* In case the key is able to serve our blocked client, let's directly
|
||||
@ -218,14 +218,14 @@ int HelloBlock_Reply(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
|
||||
/* Timeout callback for blocking command HELLOTYPE.BRANGE */
|
||||
int HelloBlock_Timeout(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
return RedisModule_ReplyWithSimpleString(ctx,"Request timedout");
|
||||
}
|
||||
|
||||
/* Private data freeing callback for HELLOTYPE.BRANGE command. */
|
||||
void HelloBlock_FreeData(RedisModuleCtx *ctx, void *privdata) {
|
||||
REDISMODULE_NOT_USED(ctx);
|
||||
VALKEYMODULE_NOT_USED(ctx);
|
||||
RedisModule_Free(privdata);
|
||||
}
|
||||
|
||||
@ -236,31 +236,31 @@ int HelloTypeBRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
if (argc != 5) return RedisModule_WrongArity(ctx);
|
||||
RedisModule_AutoMemory(ctx); /* Use automatic memory management. */
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_EMPTY &&
|
||||
if (type != VALKEYMODULE_KEYTYPE_EMPTY &&
|
||||
RedisModule_ModuleTypeGetType(key) != HelloType)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
/* Parse the timeout before even trying to serve the client synchronously,
|
||||
* so that we always fail ASAP on syntax errors. */
|
||||
long long timeout;
|
||||
if (RedisModule_StringToLongLong(argv[4],&timeout) != REDISMODULE_OK) {
|
||||
if (RedisModule_StringToLongLong(argv[4],&timeout) != VALKEYMODULE_OK) {
|
||||
return RedisModule_ReplyWithError(ctx,
|
||||
"ERR invalid timeout parameter");
|
||||
}
|
||||
|
||||
/* Can we serve the reply synchronously? */
|
||||
if (type != REDISMODULE_KEYTYPE_EMPTY) {
|
||||
if (type != VALKEYMODULE_KEYTYPE_EMPTY) {
|
||||
return HelloTypeRange_RedisCommand(ctx,argv,argc-1);
|
||||
}
|
||||
|
||||
/* Otherwise let's block on the key. */
|
||||
void *privdata = RedisModule_Alloc(100);
|
||||
RedisModule_BlockClientOnKeys(ctx,HelloBlock_Reply,HelloBlock_Timeout,HelloBlock_FreeData,timeout,argv+1,1,privdata);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* ========================== "hellotype" type methods ======================= */
|
||||
@ -323,14 +323,14 @@ void HelloTypeDigest(RedisModuleDigest *md, void *value) {
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
|
||||
if (RedisModule_Init(ctx,"hellotype",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"hellotype",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
RedisModuleTypeMethods tm = {
|
||||
.version = REDISMODULE_TYPE_METHOD_VERSION,
|
||||
.version = VALKEYMODULE_TYPE_METHOD_VERSION,
|
||||
.rdb_load = HelloTypeRdbLoad,
|
||||
.rdb_save = HelloTypeRdbSave,
|
||||
.aof_rewrite = HelloTypeAofRewrite,
|
||||
@ -340,23 +340,23 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
};
|
||||
|
||||
HelloType = RedisModule_CreateDataType(ctx,"hellotype",0,&tm);
|
||||
if (HelloType == NULL) return REDISMODULE_ERR;
|
||||
if (HelloType == NULL) return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellotype.insert",
|
||||
HelloTypeInsert_RedisCommand,"write deny-oom",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloTypeInsert_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellotype.range",
|
||||
HelloTypeRange_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloTypeRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellotype.len",
|
||||
HelloTypeLen_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloTypeLen_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hellotype.brange",
|
||||
HelloTypeBRange_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloTypeBRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "../redismodule.h"
|
||||
#include "../valkeymodule.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
@ -46,10 +46,10 @@
|
||||
* fetch the currently selected DB, the other in order to send the client
|
||||
* an integer reply as response. */
|
||||
int HelloSimple_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
RedisModule_ReplyWithLongLong(ctx,RedisModule_GetSelectedDb(ctx));
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.PUSH.NATIVE re-implements RPUSH, and shows the low level modules API
|
||||
@ -63,13 +63,13 @@ int HelloPushNative_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
if (argc != 3) return RedisModule_WrongArity(ctx);
|
||||
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
|
||||
RedisModule_ListPush(key,REDISMODULE_LIST_TAIL,argv[2]);
|
||||
RedisModule_ListPush(key,VALKEYMODULE_LIST_TAIL,argv[2]);
|
||||
size_t newlen = RedisModule_ValueLength(key);
|
||||
RedisModule_CloseKey(key);
|
||||
RedisModule_ReplyWithLongLong(ctx,newlen);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.PUSH.CALL implements RPUSH using an higher level approach, calling
|
||||
@ -87,7 +87,7 @@ int HelloPushCall_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
|
||||
long long len = RedisModule_CallReplyInteger(reply);
|
||||
RedisModule_FreeCallReply(reply);
|
||||
RedisModule_ReplyWithLongLong(ctx,len);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.PUSH.CALL2
|
||||
@ -102,7 +102,7 @@ int HelloPushCall2_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
reply = RedisModule_Call(ctx,"RPUSH","ss",argv[1],argv[2]);
|
||||
RedisModule_ReplyWithCallReply(ctx,reply);
|
||||
RedisModule_FreeCallReply(reply);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.LIST.SUM.LEN returns the total length of all the items inside
|
||||
@ -124,7 +124,7 @@ int HelloListSumLen_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
}
|
||||
RedisModule_FreeCallReply(reply);
|
||||
RedisModule_ReplyWithLongLong(ctx,strlen);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.LIST.SPLICE srclist dstlist count
|
||||
@ -135,23 +135,23 @@ int HelloListSplice_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
if (argc != 4) return RedisModule_WrongArity(ctx);
|
||||
|
||||
RedisModuleKey *srckey = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
RedisModuleKey *dstkey = RedisModule_OpenKey(ctx,argv[2],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
|
||||
/* Src and dst key must be empty or lists. */
|
||||
if ((RedisModule_KeyType(srckey) != REDISMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(srckey) != REDISMODULE_KEYTYPE_EMPTY) ||
|
||||
(RedisModule_KeyType(dstkey) != REDISMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(dstkey) != REDISMODULE_KEYTYPE_EMPTY))
|
||||
if ((RedisModule_KeyType(srckey) != VALKEYMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(srckey) != VALKEYMODULE_KEYTYPE_EMPTY) ||
|
||||
(RedisModule_KeyType(dstkey) != VALKEYMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(dstkey) != VALKEYMODULE_KEYTYPE_EMPTY))
|
||||
{
|
||||
RedisModule_CloseKey(srckey);
|
||||
RedisModule_CloseKey(dstkey);
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
long long count;
|
||||
if ((RedisModule_StringToLongLong(argv[3],&count) != REDISMODULE_OK) ||
|
||||
if ((RedisModule_StringToLongLong(argv[3],&count) != VALKEYMODULE_OK) ||
|
||||
(count < 0)) {
|
||||
RedisModule_CloseKey(srckey);
|
||||
RedisModule_CloseKey(dstkey);
|
||||
@ -161,9 +161,9 @@ int HelloListSplice_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
while(count-- > 0) {
|
||||
RedisModuleString *ele;
|
||||
|
||||
ele = RedisModule_ListPop(srckey,REDISMODULE_LIST_TAIL);
|
||||
ele = RedisModule_ListPop(srckey,VALKEYMODULE_LIST_TAIL);
|
||||
if (ele == NULL) break;
|
||||
RedisModule_ListPush(dstkey,REDISMODULE_LIST_HEAD,ele);
|
||||
RedisModule_ListPush(dstkey,VALKEYMODULE_LIST_HEAD,ele);
|
||||
RedisModule_FreeString(ctx,ele);
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ int HelloListSplice_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
RedisModule_CloseKey(srckey);
|
||||
RedisModule_CloseKey(dstkey);
|
||||
RedisModule_ReplyWithLongLong(ctx,len);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* Like the HELLO.LIST.SPLICE above, but uses automatic memory management
|
||||
@ -182,21 +182,21 @@ int HelloListSpliceAuto_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **ar
|
||||
RedisModule_AutoMemory(ctx);
|
||||
|
||||
RedisModuleKey *srckey = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
RedisModuleKey *dstkey = RedisModule_OpenKey(ctx,argv[2],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
|
||||
/* Src and dst key must be empty or lists. */
|
||||
if ((RedisModule_KeyType(srckey) != REDISMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(srckey) != REDISMODULE_KEYTYPE_EMPTY) ||
|
||||
(RedisModule_KeyType(dstkey) != REDISMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(dstkey) != REDISMODULE_KEYTYPE_EMPTY))
|
||||
if ((RedisModule_KeyType(srckey) != VALKEYMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(srckey) != VALKEYMODULE_KEYTYPE_EMPTY) ||
|
||||
(RedisModule_KeyType(dstkey) != VALKEYMODULE_KEYTYPE_LIST &&
|
||||
RedisModule_KeyType(dstkey) != VALKEYMODULE_KEYTYPE_EMPTY))
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
long long count;
|
||||
if ((RedisModule_StringToLongLong(argv[3],&count) != REDISMODULE_OK) ||
|
||||
if ((RedisModule_StringToLongLong(argv[3],&count) != VALKEYMODULE_OK) ||
|
||||
(count < 0))
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid count");
|
||||
@ -205,14 +205,14 @@ int HelloListSpliceAuto_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **ar
|
||||
while(count-- > 0) {
|
||||
RedisModuleString *ele;
|
||||
|
||||
ele = RedisModule_ListPop(srckey,REDISMODULE_LIST_TAIL);
|
||||
ele = RedisModule_ListPop(srckey,VALKEYMODULE_LIST_TAIL);
|
||||
if (ele == NULL) break;
|
||||
RedisModule_ListPush(dstkey,REDISMODULE_LIST_HEAD,ele);
|
||||
RedisModule_ListPush(dstkey,VALKEYMODULE_LIST_HEAD,ele);
|
||||
}
|
||||
|
||||
size_t len = RedisModule_ValueLength(srckey);
|
||||
RedisModule_ReplyWithLongLong(ctx,len);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.RAND.ARRAY <count>
|
||||
@ -221,7 +221,7 @@ int HelloListSpliceAuto_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **ar
|
||||
int HelloRandArray_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
if (argc != 2) return RedisModule_WrongArity(ctx);
|
||||
long long count;
|
||||
if (RedisModule_StringToLongLong(argv[1],&count) != REDISMODULE_OK ||
|
||||
if (RedisModule_StringToLongLong(argv[1],&count) != VALKEYMODULE_OK ||
|
||||
count < 0)
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid count");
|
||||
|
||||
@ -230,7 +230,7 @@ int HelloRandArray_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
* the elements of the array. */
|
||||
RedisModule_ReplyWithArray(ctx,count);
|
||||
while(count--) RedisModule_ReplyWithLongLong(ctx,rand());
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This is a simple command to test replication. Because of the "!" modified
|
||||
@ -239,8 +239,8 @@ int HelloRandArray_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
* comments the function implementation). */
|
||||
int HelloRepl1_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
{
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
REDISMODULE_NOT_USED(argc);
|
||||
VALKEYMODULE_NOT_USED(argv);
|
||||
VALKEYMODULE_NOT_USED(argc);
|
||||
RedisModule_AutoMemory(ctx);
|
||||
|
||||
/* This will be replicated *after* the two INCR statements, since
|
||||
@ -262,7 +262,7 @@ int HelloRepl1_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
|
||||
|
||||
RedisModule_ReplyWithLongLong(ctx,0);
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* Another command to show replication. In this case, we call
|
||||
@ -280,27 +280,27 @@ int HelloRepl2_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
|
||||
|
||||
RedisModule_AutoMemory(ctx); /* Use automatic memory management. */
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
|
||||
if (RedisModule_KeyType(key) != REDISMODULE_KEYTYPE_LIST)
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
if (RedisModule_KeyType(key) != VALKEYMODULE_KEYTYPE_LIST)
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
|
||||
size_t listlen = RedisModule_ValueLength(key);
|
||||
long long sum = 0;
|
||||
|
||||
/* Rotate and increment. */
|
||||
while(listlen--) {
|
||||
RedisModuleString *ele = RedisModule_ListPop(key,REDISMODULE_LIST_TAIL);
|
||||
RedisModuleString *ele = RedisModule_ListPop(key,VALKEYMODULE_LIST_TAIL);
|
||||
long long val;
|
||||
if (RedisModule_StringToLongLong(ele,&val) != REDISMODULE_OK) val = 0;
|
||||
if (RedisModule_StringToLongLong(ele,&val) != VALKEYMODULE_OK) val = 0;
|
||||
val++;
|
||||
sum += val;
|
||||
RedisModuleString *newele = RedisModule_CreateStringFromLongLong(ctx,val);
|
||||
RedisModule_ListPush(key,REDISMODULE_LIST_HEAD,newele);
|
||||
RedisModule_ListPush(key,VALKEYMODULE_LIST_HEAD,newele);
|
||||
}
|
||||
RedisModule_ReplyWithLongLong(ctx,sum);
|
||||
RedisModule_ReplicateVerbatim(ctx);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This is an example of strings DMA access. Given a key containing a string
|
||||
@ -315,19 +315,19 @@ int HelloToggleCase_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
if (argc != 2) return RedisModule_WrongArity(ctx);
|
||||
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
|
||||
int keytype = RedisModule_KeyType(key);
|
||||
if (keytype != REDISMODULE_KEYTYPE_STRING &&
|
||||
keytype != REDISMODULE_KEYTYPE_EMPTY)
|
||||
if (keytype != VALKEYMODULE_KEYTYPE_STRING &&
|
||||
keytype != VALKEYMODULE_KEYTYPE_EMPTY)
|
||||
{
|
||||
RedisModule_CloseKey(key);
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
if (keytype == REDISMODULE_KEYTYPE_STRING) {
|
||||
if (keytype == VALKEYMODULE_KEYTYPE_STRING) {
|
||||
size_t len, j;
|
||||
char *s = RedisModule_StringDMA(key,&len,REDISMODULE_WRITE);
|
||||
char *s = RedisModule_StringDMA(key,&len,VALKEYMODULE_WRITE);
|
||||
for (j = 0; j < len; j++) {
|
||||
if (isupper(s[j])) {
|
||||
s[j] = tolower(s[j]);
|
||||
@ -340,7 +340,7 @@ int HelloToggleCase_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
RedisModule_CloseKey(key);
|
||||
RedisModule_ReplyWithSimpleString(ctx,"OK");
|
||||
RedisModule_ReplicateVerbatim(ctx);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.MORE.EXPIRE key milliseconds.
|
||||
@ -353,13 +353,13 @@ int HelloMoreExpire_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv,
|
||||
|
||||
mstime_t addms, expire;
|
||||
|
||||
if (RedisModule_StringToLongLong(argv[2],&addms) != REDISMODULE_OK)
|
||||
if (RedisModule_StringToLongLong(argv[2],&addms) != VALKEYMODULE_OK)
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid expire time");
|
||||
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
expire = RedisModule_GetExpire(key);
|
||||
if (expire != REDISMODULE_NO_EXPIRE) {
|
||||
if (expire != VALKEYMODULE_NO_EXPIRE) {
|
||||
expire += addms;
|
||||
RedisModule_SetExpire(key,expire);
|
||||
}
|
||||
@ -376,16 +376,16 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
double score_start, score_end;
|
||||
if (argc != 4) return RedisModule_WrongArity(ctx);
|
||||
|
||||
if (RedisModule_StringToDouble(argv[2],&score_start) != REDISMODULE_OK ||
|
||||
RedisModule_StringToDouble(argv[3],&score_end) != REDISMODULE_OK)
|
||||
if (RedisModule_StringToDouble(argv[2],&score_start) != VALKEYMODULE_OK ||
|
||||
RedisModule_StringToDouble(argv[3],&score_end) != VALKEYMODULE_OK)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid range");
|
||||
}
|
||||
|
||||
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);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
if (RedisModule_KeyType(key) != VALKEYMODULE_KEYTYPE_ZSET) {
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
double scoresum_a = 0;
|
||||
@ -417,7 +417,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
||||
RedisModule_ReplyWithArray(ctx,2);
|
||||
RedisModule_ReplyWithDouble(ctx,scoresum_a);
|
||||
RedisModule_ReplyWithDouble(ctx,scoresum_b);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.LEXRANGE key min_lex max_lex min_age max_age
|
||||
@ -433,17 +433,17 @@ int HelloLexRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
|
||||
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);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
if (RedisModule_KeyType(key) != VALKEYMODULE_KEYTYPE_ZSET) {
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
if (RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]) != REDISMODULE_OK) {
|
||||
if (RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]) != VALKEYMODULE_OK) {
|
||||
return RedisModule_ReplyWithError(ctx,"invalid range");
|
||||
}
|
||||
|
||||
int arraylen = 0;
|
||||
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_LEN);
|
||||
RedisModule_ReplyWithArray(ctx,VALKEYMODULE_POSTPONED_LEN);
|
||||
while(!RedisModule_ZsetRangeEndReached(key)) {
|
||||
double score;
|
||||
RedisModuleString *ele = RedisModule_ZsetRangeCurrentElement(key,&score);
|
||||
@ -455,7 +455,7 @@ int HelloLexRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, in
|
||||
RedisModule_ZsetRangeStop(key);
|
||||
RedisModule_ReplySetArrayLength(ctx,arraylen);
|
||||
RedisModule_CloseKey(key);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.HCOPY key srcfield dstfield
|
||||
@ -470,22 +470,22 @@ int HelloHCopy_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int a
|
||||
|
||||
if (argc != 4) return RedisModule_WrongArity(ctx);
|
||||
RedisModuleKey *key = RedisModule_OpenKey(ctx,argv[1],
|
||||
REDISMODULE_READ|REDISMODULE_WRITE);
|
||||
VALKEYMODULE_READ|VALKEYMODULE_WRITE);
|
||||
int type = RedisModule_KeyType(key);
|
||||
if (type != REDISMODULE_KEYTYPE_HASH &&
|
||||
type != REDISMODULE_KEYTYPE_EMPTY)
|
||||
if (type != VALKEYMODULE_KEYTYPE_HASH &&
|
||||
type != VALKEYMODULE_KEYTYPE_EMPTY)
|
||||
{
|
||||
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||
return RedisModule_ReplyWithError(ctx,VALKEYMODULE_ERRORMSG_WRONGTYPE);
|
||||
}
|
||||
|
||||
/* Get the old field value. */
|
||||
RedisModuleString *oldval;
|
||||
RedisModule_HashGet(key,REDISMODULE_HASH_NONE,argv[2],&oldval,NULL);
|
||||
RedisModule_HashGet(key,VALKEYMODULE_HASH_NONE,argv[2],&oldval,NULL);
|
||||
if (oldval) {
|
||||
RedisModule_HashSet(key,REDISMODULE_HASH_NONE,argv[3],oldval,NULL);
|
||||
RedisModule_HashSet(key,VALKEYMODULE_HASH_NONE,argv[3],oldval,NULL);
|
||||
}
|
||||
RedisModule_ReplyWithLongLong(ctx,oldval != NULL);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* HELLO.LEFTPAD str len ch
|
||||
@ -512,7 +512,7 @@ int HelloLeftPad_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
|
||||
if (argc != 4) return RedisModule_WrongArity(ctx);
|
||||
|
||||
if ((RedisModule_StringToLongLong(argv[2],&padlen) != REDISMODULE_OK) ||
|
||||
if ((RedisModule_StringToLongLong(argv[2],&padlen) != VALKEYMODULE_OK) ||
|
||||
(padlen< 0)) {
|
||||
return RedisModule_ReplyWithError(ctx,"ERR invalid padding length");
|
||||
}
|
||||
@ -537,14 +537,14 @@ int HelloLeftPad_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
|
||||
memcpy(buf+padlen,str,strlen);
|
||||
|
||||
RedisModule_ReplyWithStringBuffer(ctx,buf,padlen+strlen);
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
/* This function must be present on each Redis module. It is used in order to
|
||||
* register the commands into the Redis server. */
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
if (RedisModule_Init(ctx,"helloworld",1,REDISMODULE_APIVER_1)
|
||||
== REDISMODULE_ERR) return REDISMODULE_ERR;
|
||||
if (RedisModule_Init(ctx,"helloworld",1,VALKEYMODULE_APIVER_1)
|
||||
== VALKEYMODULE_ERR) return VALKEYMODULE_ERR;
|
||||
|
||||
/* Log the list of parameters passing loading the module. */
|
||||
for (int j = 0; j < argc; j++) {
|
||||
@ -553,69 +553,69 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
}
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.simple",
|
||||
HelloSimple_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloSimple_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.push.native",
|
||||
HelloPushNative_RedisCommand,"write deny-oom",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloPushNative_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.push.call",
|
||||
HelloPushCall_RedisCommand,"write deny-oom",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloPushCall_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.push.call2",
|
||||
HelloPushCall2_RedisCommand,"write deny-oom",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloPushCall2_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.list.sum.len",
|
||||
HelloListSumLen_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloListSumLen_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.list.splice",
|
||||
HelloListSplice_RedisCommand,"write deny-oom",1,2,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloListSplice_RedisCommand,"write deny-oom",1,2,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.list.splice.auto",
|
||||
HelloListSpliceAuto_RedisCommand,
|
||||
"write deny-oom",1,2,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
"write deny-oom",1,2,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.rand.array",
|
||||
HelloRandArray_RedisCommand,"readonly",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloRandArray_RedisCommand,"readonly",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.repl1",
|
||||
HelloRepl1_RedisCommand,"write",0,0,0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloRepl1_RedisCommand,"write",0,0,0) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.repl2",
|
||||
HelloRepl2_RedisCommand,"write",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloRepl2_RedisCommand,"write",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.toggle.case",
|
||||
HelloToggleCase_RedisCommand,"write",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloToggleCase_RedisCommand,"write",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.more.expire",
|
||||
HelloMoreExpire_RedisCommand,"write",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloMoreExpire_RedisCommand,"write",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.zsumrange",
|
||||
HelloZsumRange_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloZsumRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.lexrange",
|
||||
HelloLexRange_RedisCommand,"readonly",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloLexRange_RedisCommand,"readonly",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.hcopy",
|
||||
HelloHCopy_RedisCommand,"write deny-oom",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloHCopy_RedisCommand,"write deny-oom",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx,"hello.leftpad",
|
||||
HelloLeftPad_RedisCommand,"",1,1,1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
HelloLeftPad_RedisCommand,"",1,1,1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
@ -1309,8 +1309,8 @@ void clientAcceptHandler(connection *conn) {
|
||||
}
|
||||
|
||||
server.stat_numconnections++;
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_CLIENT_CHANGE,
|
||||
REDISMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_CLIENT_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_CLIENT_CHANGE_CONNECTED,
|
||||
c);
|
||||
}
|
||||
|
||||
@ -1574,8 +1574,8 @@ void freeClient(client *c) {
|
||||
|
||||
/* For connected clients, call the disconnection event of modules hooks. */
|
||||
if (c->conn) {
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_CLIENT_CHANGE,
|
||||
REDISMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_CLIENT_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_CLIENT_CHANGE_DISCONNECTED,
|
||||
c);
|
||||
}
|
||||
|
||||
@ -1695,8 +1695,8 @@ void freeClient(client *c) {
|
||||
refreshGoodSlavesCount();
|
||||
/* Fire the replica change modules event. */
|
||||
if (c->replstate == SLAVE_STATE_ONLINE)
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPLICA_CHANGE,
|
||||
REDISMODULE_SUBEVENT_REPLICA_CHANGE_OFFLINE,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICA_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_REPLICA_CHANGE_OFFLINE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
|
44
src/rdb.c
44
src/rdb.c
@ -1079,7 +1079,7 @@ ssize_t rdbSaveObject(rio *rdb, robj *o, robj *key, int dbid) {
|
||||
}
|
||||
} else if (o->type == OBJ_MODULE) {
|
||||
/* Save a module-specific value. */
|
||||
RedisModuleIO io;
|
||||
ValkeyModuleIO io;
|
||||
moduleValue *mv = o->ptr;
|
||||
moduleType *mt = mv->type;
|
||||
|
||||
@ -1217,7 +1217,7 @@ int rdbSaveInfoAuxFields(rio *rdb, int rdbflags, rdbSaveInfo *rsi) {
|
||||
|
||||
ssize_t rdbSaveSingleModuleAux(rio *rdb, int when, moduleType *mt) {
|
||||
/* Save a module-specific aux value. */
|
||||
RedisModuleIO io;
|
||||
ValkeyModuleIO io;
|
||||
int retval = 0;
|
||||
moduleInitIOContext(io,mt,rdb,NULL,-1);
|
||||
|
||||
@ -1397,7 +1397,7 @@ int rdbSaveRio(int req, rio *rdb, int *error, int rdbflags, rdbSaveInfo *rsi) {
|
||||
snprintf(magic,sizeof(magic),"REDIS%04d",RDB_VERSION);
|
||||
if (rdbWriteRaw(rdb,magic,9) == -1) goto werr;
|
||||
if (rdbSaveInfoAuxFields(rdb,rdbflags,rsi) == -1) goto werr;
|
||||
if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, REDISMODULE_AUX_BEFORE_RDB) == -1) goto werr;
|
||||
if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_BEFORE_RDB) == -1) goto werr;
|
||||
|
||||
/* save functions */
|
||||
if (!(req & SLAVE_REQ_RDB_EXCLUDE_FUNCTIONS) && rdbSaveFunctions(rdb) == -1) goto werr;
|
||||
@ -1409,7 +1409,7 @@ int rdbSaveRio(int req, rio *rdb, int *error, int rdbflags, rdbSaveInfo *rsi) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, REDISMODULE_AUX_AFTER_RDB) == -1) goto werr;
|
||||
if (!(req & SLAVE_REQ_RDB_EXCLUDE_DATA) && rdbSaveModulesAux(rdb, VALKEYMODULE_AUX_AFTER_RDB) == -1) goto werr;
|
||||
|
||||
/* EOF opcode */
|
||||
if (rdbSaveType(rdb,RDB_OPCODE_EOF) == -1) goto werr;
|
||||
@ -2814,7 +2814,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) {
|
||||
rdbReportCorruptRDB("The RDB file contains module data I can't load: no matching module type '%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
RedisModuleIO io;
|
||||
ValkeyModuleIO io;
|
||||
robj keyobj;
|
||||
initStaticStringObject(keyobj,key);
|
||||
moduleInitIOContext(io,mt,rdb,&keyobj,dbid);
|
||||
@ -2881,12 +2881,12 @@ void startLoading(size_t size, int rdbflags, int async) {
|
||||
/* Fire the loading modules start event. */
|
||||
int subevent;
|
||||
if (rdbflags & RDBFLAGS_AOF_PREAMBLE)
|
||||
subevent = REDISMODULE_SUBEVENT_LOADING_AOF_START;
|
||||
subevent = VALKEYMODULE_SUBEVENT_LOADING_AOF_START;
|
||||
else if(rdbflags & RDBFLAGS_REPLICATION)
|
||||
subevent = REDISMODULE_SUBEVENT_LOADING_REPL_START;
|
||||
subevent = VALKEYMODULE_SUBEVENT_LOADING_REPL_START;
|
||||
else
|
||||
subevent = REDISMODULE_SUBEVENT_LOADING_RDB_START;
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_LOADING,subevent,NULL);
|
||||
subevent = VALKEYMODULE_SUBEVENT_LOADING_RDB_START;
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_LOADING,subevent,NULL);
|
||||
}
|
||||
|
||||
/* Mark that we are loading in the global state and setup the fields
|
||||
@ -2924,10 +2924,10 @@ void stopLoading(int success) {
|
||||
rdbFileBeingLoaded = NULL;
|
||||
|
||||
/* Fire the loading modules end event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_LOADING,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_LOADING,
|
||||
success?
|
||||
REDISMODULE_SUBEVENT_LOADING_ENDED:
|
||||
REDISMODULE_SUBEVENT_LOADING_FAILED,
|
||||
VALKEYMODULE_SUBEVENT_LOADING_ENDED:
|
||||
VALKEYMODULE_SUBEVENT_LOADING_FAILED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -2935,22 +2935,22 @@ void startSaving(int rdbflags) {
|
||||
/* Fire the persistence modules start event. */
|
||||
int subevent;
|
||||
if (rdbflags & RDBFLAGS_AOF_PREAMBLE && getpid() != server.pid)
|
||||
subevent = REDISMODULE_SUBEVENT_PERSISTENCE_AOF_START;
|
||||
subevent = VALKEYMODULE_SUBEVENT_PERSISTENCE_AOF_START;
|
||||
else if (rdbflags & RDBFLAGS_AOF_PREAMBLE)
|
||||
subevent = REDISMODULE_SUBEVENT_PERSISTENCE_SYNC_AOF_START;
|
||||
subevent = VALKEYMODULE_SUBEVENT_PERSISTENCE_SYNC_AOF_START;
|
||||
else if (getpid()!=server.pid)
|
||||
subevent = REDISMODULE_SUBEVENT_PERSISTENCE_RDB_START;
|
||||
subevent = VALKEYMODULE_SUBEVENT_PERSISTENCE_RDB_START;
|
||||
else
|
||||
subevent = REDISMODULE_SUBEVENT_PERSISTENCE_SYNC_RDB_START;
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_PERSISTENCE,subevent,NULL);
|
||||
subevent = VALKEYMODULE_SUBEVENT_PERSISTENCE_SYNC_RDB_START;
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PERSISTENCE,subevent,NULL);
|
||||
}
|
||||
|
||||
void stopSaving(int success) {
|
||||
/* Fire the persistence modules end event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_PERSISTENCE,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PERSISTENCE,
|
||||
success?
|
||||
REDISMODULE_SUBEVENT_PERSISTENCE_ENDED:
|
||||
REDISMODULE_SUBEVENT_PERSISTENCE_FAILED,
|
||||
VALKEYMODULE_SUBEVENT_PERSISTENCE_ENDED:
|
||||
VALKEYMODULE_SUBEVENT_PERSISTENCE_FAILED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -3224,7 +3224,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
|
||||
exit(1);
|
||||
}
|
||||
|
||||
RedisModuleIO io;
|
||||
ValkeyModuleIO io;
|
||||
moduleInitIOContext(io,mt,rdb,NULL,-1);
|
||||
/* Call the rdb_load method of the module providing the 10 bit
|
||||
* encoding version in the lower 10 bits of the module ID. */
|
||||
@ -3233,7 +3233,7 @@ int rdbLoadRioWithLoadingCtx(rio *rdb, int rdbflags, rdbSaveInfo *rsi, rdbLoadin
|
||||
moduleFreeContext(io.ctx);
|
||||
zfree(io.ctx);
|
||||
}
|
||||
if (rc != REDISMODULE_OK || io.error) {
|
||||
if (rc != VALKEYMODULE_OK || io.error) {
|
||||
moduleTypeNameByID(name,moduleid);
|
||||
serverLog(LL_WARNING,"The RDB file contains module AUX data for the module type '%s', that the responsible module is not able to load. Check for modules log above for additional clues.", name);
|
||||
goto eoferr;
|
||||
|
2396
src/redismodule.h
2396
src/redismodule.h
File diff suppressed because it is too large
Load Diff
@ -821,8 +821,8 @@ int masterTryPartialResynchronization(client *c, long long psync_offset) {
|
||||
refreshGoodSlavesCount();
|
||||
|
||||
/* Fire the replica change modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPLICA_CHANGE,
|
||||
REDISMODULE_SUBEVENT_REPLICA_CHANGE_ONLINE,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICA_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_REPLICA_CHANGE_ONLINE,
|
||||
NULL);
|
||||
|
||||
return C_OK; /* The caller can return, no full resync needed. */
|
||||
@ -1308,8 +1308,8 @@ int replicaPutOnline(client *slave) {
|
||||
|
||||
refreshGoodSlavesCount();
|
||||
/* Fire the replica change modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPLICA_CHANGE,
|
||||
REDISMODULE_SUBEVENT_REPLICA_CHANGE_ONLINE,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICA_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_REPLICA_CHANGE_ONLINE,
|
||||
NULL);
|
||||
serverLog(LL_NOTICE,"Synchronization with replica %s succeeded",
|
||||
replicationGetSlaveName(slave));
|
||||
@ -2068,8 +2068,8 @@ void readSyncBulkPayload(connection *conn) {
|
||||
diskless_load_tempDb = disklessLoadInitTempDb();
|
||||
temp_functions_lib_ctx = functionsLibCtxCreate();
|
||||
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
REDISMODULE_SUBEVENT_REPL_ASYNC_LOAD_STARTED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
VALKEYMODULE_SUBEVENT_REPL_ASYNC_LOAD_STARTED,
|
||||
NULL);
|
||||
} else {
|
||||
replicationAttachToNewMaster();
|
||||
@ -2142,8 +2142,8 @@ void readSyncBulkPayload(connection *conn) {
|
||||
|
||||
if (server.repl_diskless_load == REPL_DISKLESS_LOAD_SWAPDB) {
|
||||
/* Discard potentially partially loaded tempDb. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
REDISMODULE_SUBEVENT_REPL_ASYNC_LOAD_ABORTED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
VALKEYMODULE_SUBEVENT_REPL_ASYNC_LOAD_ABORTED,
|
||||
NULL);
|
||||
|
||||
disklessLoadDiscardTempDb(diskless_load_tempDb);
|
||||
@ -2173,8 +2173,8 @@ void readSyncBulkPayload(connection *conn) {
|
||||
/* swap existing functions ctx with the temporary one */
|
||||
functionsLibCtxSwapWithCurrent(temp_functions_lib_ctx);
|
||||
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
REDISMODULE_SUBEVENT_REPL_ASYNC_LOAD_COMPLETED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPL_ASYNC_LOAD,
|
||||
VALKEYMODULE_SUBEVENT_REPL_ASYNC_LOAD_COMPLETED,
|
||||
NULL);
|
||||
|
||||
/* Delete the old db as it's useless now. */
|
||||
@ -2269,8 +2269,8 @@ void readSyncBulkPayload(connection *conn) {
|
||||
server.repl_down_since = 0;
|
||||
|
||||
/* Fire the master link modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
|
||||
REDISMODULE_SUBEVENT_MASTER_LINK_UP,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_PRIMARY_LINK_UP,
|
||||
NULL);
|
||||
|
||||
/* After a full resynchronization we use the replication ID and
|
||||
@ -3044,14 +3044,14 @@ void replicationSetMaster(char *ip, int port) {
|
||||
}
|
||||
|
||||
/* Fire the role change modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED,
|
||||
REDISMODULE_EVENT_REPLROLECHANGED_NOW_REPLICA,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICATION_ROLE_CHANGED,
|
||||
VALKEYMODULE_EVENT_REPLROLECHANGED_NOW_REPLICA,
|
||||
NULL);
|
||||
|
||||
/* Fire the master link modules event. */
|
||||
if (server.repl_state == REPL_STATE_CONNECTED)
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
|
||||
REDISMODULE_SUBEVENT_MASTER_LINK_DOWN,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_PRIMARY_LINK_DOWN,
|
||||
NULL);
|
||||
|
||||
server.repl_state = REPL_STATE_CONNECT;
|
||||
@ -3066,8 +3066,8 @@ void replicationUnsetMaster(void) {
|
||||
|
||||
/* Fire the master link modules event. */
|
||||
if (server.repl_state == REPL_STATE_CONNECTED)
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
|
||||
REDISMODULE_SUBEVENT_MASTER_LINK_DOWN,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_PRIMARY_LINK_DOWN,
|
||||
NULL);
|
||||
|
||||
/* Clear masterhost first, since the freeClient calls
|
||||
@ -3108,8 +3108,8 @@ void replicationUnsetMaster(void) {
|
||||
server.repl_down_since = 0;
|
||||
|
||||
/* Fire the role change modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED,
|
||||
REDISMODULE_EVENT_REPLROLECHANGED_NOW_MASTER,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_REPLICATION_ROLE_CHANGED,
|
||||
VALKEYMODULE_EVENT_REPLROLECHANGED_NOW_PRIMARY,
|
||||
NULL);
|
||||
|
||||
/* Restart the AOF subsystem in case we shut it down during a sync when
|
||||
@ -3122,8 +3122,8 @@ void replicationUnsetMaster(void) {
|
||||
void replicationHandleMasterDisconnection(void) {
|
||||
/* Fire the master link modules event. */
|
||||
if (server.repl_state == REPL_STATE_CONNECTED)
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
|
||||
REDISMODULE_SUBEVENT_MASTER_LINK_DOWN,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_PRIMARY_LINK_DOWN,
|
||||
NULL);
|
||||
|
||||
server.master = NULL;
|
||||
@ -3411,8 +3411,8 @@ void replicationResurrectCachedMaster(connection *conn) {
|
||||
server.repl_down_since = 0;
|
||||
|
||||
/* Fire the master link modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
|
||||
REDISMODULE_SUBEVENT_MASTER_LINK_UP,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_PRIMARY_LINK_CHANGE,
|
||||
VALKEYMODULE_SUBEVENT_PRIMARY_LINK_UP,
|
||||
NULL);
|
||||
|
||||
/* Re-add to the list of clients. */
|
||||
|
24
src/server.c
24
src/server.c
@ -568,7 +568,7 @@ dictType objToDictDictType = {
|
||||
};
|
||||
|
||||
/* Modules system dictionary type. Keys are module name,
|
||||
* values are pointer to RedisModule struct. */
|
||||
* values are pointer to ValkeyModule struct. */
|
||||
dictType modulesDictType = {
|
||||
dictSdsCaseHash, /* hash function */
|
||||
NULL, /* key dup */
|
||||
@ -677,8 +677,8 @@ void resetChildState(void) {
|
||||
server.stat_current_save_keys_total = 0;
|
||||
updateDictResizePolicy();
|
||||
closeChildInfoPipe();
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_FORK_CHILD,
|
||||
REDISMODULE_SUBEVENT_FORK_CHILD_DIED,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_FORK_CHILD,
|
||||
VALKEYMODULE_SUBEVENT_FORK_CHILD_DIED,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -1523,8 +1523,8 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) {
|
||||
}
|
||||
|
||||
/* Fire the cron loop modules event. */
|
||||
RedisModuleCronLoopV1 ei = {REDISMODULE_CRON_LOOP_VERSION,server.hz};
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_CRON_LOOP,
|
||||
ValkeyModuleCronLoopV1 ei = {VALKEYMODULE_CRON_LOOP_VERSION,server.hz};
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_CRON_LOOP,
|
||||
0,
|
||||
&ei);
|
||||
|
||||
@ -1686,8 +1686,8 @@ void beforeSleep(struct aeEventLoop *eventLoop) {
|
||||
activeExpireCycle(ACTIVE_EXPIRE_CYCLE_FAST);
|
||||
|
||||
if (moduleCount()) {
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_EVENTLOOP,
|
||||
REDISMODULE_SUBEVENT_EVENTLOOP_BEFORE_SLEEP,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_EVENTLOOP,
|
||||
VALKEYMODULE_SUBEVENT_EVENTLOOP_BEFORE_SLEEP,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@ -1816,8 +1816,8 @@ void afterSleep(struct aeEventLoop *eventLoop) {
|
||||
atomicSet(server.module_gil_acquring, 1);
|
||||
moduleAcquireGIL();
|
||||
atomicSet(server.module_gil_acquring, 0);
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_EVENTLOOP,
|
||||
REDISMODULE_SUBEVENT_EVENTLOOP_AFTER_SLEEP,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_EVENTLOOP,
|
||||
VALKEYMODULE_SUBEVENT_EVENTLOOP_AFTER_SLEEP,
|
||||
NULL);
|
||||
latencyEndMonitor(latency);
|
||||
latencyAddSampleIfNeeded("module-acquire-GIL",latency);
|
||||
@ -4502,7 +4502,7 @@ int finishShutdown(void) {
|
||||
if (server.aof_manifest) aofManifestFree(server.aof_manifest);
|
||||
|
||||
/* Fire the shutdown modules event. */
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_SHUTDOWN,0,NULL);
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_SHUTDOWN,0,NULL);
|
||||
|
||||
/* Remove the pid file if possible and needed. */
|
||||
if (server.daemonize || server.pidfile) {
|
||||
@ -6514,8 +6514,8 @@ int serverFork(int purpose) {
|
||||
}
|
||||
|
||||
updateDictResizePolicy();
|
||||
moduleFireServerEvent(REDISMODULE_EVENT_FORK_CHILD,
|
||||
REDISMODULE_SUBEVENT_FORK_CHILD_BORN,
|
||||
moduleFireServerEvent(VALKEYMODULE_EVENT_FORK_CHILD,
|
||||
VALKEYMODULE_SUBEVENT_FORK_CHILD_BORN,
|
||||
NULL);
|
||||
}
|
||||
return childpid;
|
||||
|
98
src/server.h
98
src/server.h
@ -80,9 +80,9 @@ typedef long long ustime_t; /* microsecond time type. */
|
||||
#include "rax.h" /* Radix tree */
|
||||
#include "connection.h" /* Connection abstraction */
|
||||
|
||||
#define REDISMODULE_CORE 1
|
||||
#define VALKEYMODULE_CORE 1
|
||||
typedef struct serverObject robj;
|
||||
#include "redismodule.h" /* Redis modules API defines. */
|
||||
#include "valkeymodule.h" /* Redis modules API defines. */
|
||||
|
||||
/* Following includes allow test functions to be called from Redis main() */
|
||||
#include "zipmap.h"
|
||||
@ -711,7 +711,7 @@ typedef enum {
|
||||
/* The "module" object type is a special one that signals that the object
|
||||
* is one directly managed by a Redis module. In this case the value points
|
||||
* to a moduleValue struct, which contains the object value (which is only
|
||||
* handled by the module itself) and the RedisModuleType struct which lists
|
||||
* handled by the module itself) and the ValkeyModuleType struct which lists
|
||||
* function pointers in order to serialize, deserialize, AOF-rewrite and
|
||||
* free the object.
|
||||
*
|
||||
@ -724,53 +724,53 @@ typedef enum {
|
||||
#define OBJ_TYPE_MAX 7 /* Maximum number of object types */
|
||||
|
||||
/* Extract encver / signature from a module type ID. */
|
||||
#define REDISMODULE_TYPE_ENCVER_BITS 10
|
||||
#define REDISMODULE_TYPE_ENCVER_MASK ((1<<REDISMODULE_TYPE_ENCVER_BITS)-1)
|
||||
#define REDISMODULE_TYPE_ENCVER(id) ((id) & REDISMODULE_TYPE_ENCVER_MASK)
|
||||
#define REDISMODULE_TYPE_SIGN(id) (((id) & ~((uint64_t)REDISMODULE_TYPE_ENCVER_MASK)) >>REDISMODULE_TYPE_ENCVER_BITS)
|
||||
#define VALKEYMODULE_TYPE_ENCVER_BITS 10
|
||||
#define VALKEYMODULE_TYPE_ENCVER_MASK ((1<<VALKEYMODULE_TYPE_ENCVER_BITS)-1)
|
||||
#define VALKEYMODULE_TYPE_ENCVER(id) ((id) & VALKEYMODULE_TYPE_ENCVER_MASK)
|
||||
#define VALKEYMODULE_TYPE_SIGN(id) (((id) & ~((uint64_t)VALKEYMODULE_TYPE_ENCVER_MASK)) >>VALKEYMODULE_TYPE_ENCVER_BITS)
|
||||
|
||||
/* Bit flags for moduleTypeAuxSaveFunc */
|
||||
#define REDISMODULE_AUX_BEFORE_RDB (1<<0)
|
||||
#define REDISMODULE_AUX_AFTER_RDB (1<<1)
|
||||
#define VALKEYMODULE_AUX_BEFORE_RDB (1<<0)
|
||||
#define VALKEYMODULE_AUX_AFTER_RDB (1<<1)
|
||||
|
||||
struct RedisModule;
|
||||
struct RedisModuleIO;
|
||||
struct RedisModuleDigest;
|
||||
struct RedisModuleCtx;
|
||||
struct ValkeyModule;
|
||||
struct ValkeyModuleIO;
|
||||
struct ValkeyModuleDigest;
|
||||
struct ValkeyModuleCtx;
|
||||
struct moduleLoadQueueEntry;
|
||||
struct RedisModuleKeyOptCtx;
|
||||
struct RedisModuleCommand;
|
||||
struct ValkeyModuleKeyOptCtx;
|
||||
struct ValkeyModuleCommand;
|
||||
struct clusterState;
|
||||
|
||||
/* Each module type implementation should export a set of methods in order
|
||||
* to serialize and deserialize the value in the RDB file, rewrite the AOF
|
||||
* log, create the digest for "DEBUG DIGEST", and free the value when a key
|
||||
* is deleted. */
|
||||
typedef void *(*moduleTypeLoadFunc)(struct RedisModuleIO *io, int encver);
|
||||
typedef void (*moduleTypeSaveFunc)(struct RedisModuleIO *io, void *value);
|
||||
typedef int (*moduleTypeAuxLoadFunc)(struct RedisModuleIO *rdb, int encver, int when);
|
||||
typedef void (*moduleTypeAuxSaveFunc)(struct RedisModuleIO *rdb, int when);
|
||||
typedef void (*moduleTypeRewriteFunc)(struct RedisModuleIO *io, struct serverObject *key, void *value);
|
||||
typedef void (*moduleTypeDigestFunc)(struct RedisModuleDigest *digest, void *value);
|
||||
typedef void *(*moduleTypeLoadFunc)(struct ValkeyModuleIO *io, int encver);
|
||||
typedef void (*moduleTypeSaveFunc)(struct ValkeyModuleIO *io, void *value);
|
||||
typedef int (*moduleTypeAuxLoadFunc)(struct ValkeyModuleIO *rdb, int encver, int when);
|
||||
typedef void (*moduleTypeAuxSaveFunc)(struct ValkeyModuleIO *rdb, int when);
|
||||
typedef void (*moduleTypeRewriteFunc)(struct ValkeyModuleIO *io, struct serverObject *key, void *value);
|
||||
typedef void (*moduleTypeDigestFunc)(struct ValkeyModuleDigest *digest, void *value);
|
||||
typedef size_t (*moduleTypeMemUsageFunc)(const void *value);
|
||||
typedef void (*moduleTypeFreeFunc)(void *value);
|
||||
typedef size_t (*moduleTypeFreeEffortFunc)(struct serverObject *key, const void *value);
|
||||
typedef void (*moduleTypeUnlinkFunc)(struct serverObject *key, void *value);
|
||||
typedef void *(*moduleTypeCopyFunc)(struct serverObject *fromkey, struct serverObject *tokey, const void *value);
|
||||
typedef int (*moduleTypeDefragFunc)(struct RedisModuleDefragCtx *ctx, struct serverObject *key, void **value);
|
||||
typedef size_t (*moduleTypeMemUsageFunc2)(struct RedisModuleKeyOptCtx *ctx, const void *value, size_t sample_size);
|
||||
typedef void (*moduleTypeFreeFunc2)(struct RedisModuleKeyOptCtx *ctx, void *value);
|
||||
typedef size_t (*moduleTypeFreeEffortFunc2)(struct RedisModuleKeyOptCtx *ctx, const void *value);
|
||||
typedef void (*moduleTypeUnlinkFunc2)(struct RedisModuleKeyOptCtx *ctx, void *value);
|
||||
typedef void *(*moduleTypeCopyFunc2)(struct RedisModuleKeyOptCtx *ctx, const void *value);
|
||||
typedef int (*moduleTypeAuthCallback)(struct RedisModuleCtx *ctx, void *username, void *password, const char **err);
|
||||
typedef int (*moduleTypeDefragFunc)(struct ValkeyModuleDefragCtx *ctx, struct serverObject *key, void **value);
|
||||
typedef size_t (*moduleTypeMemUsageFunc2)(struct ValkeyModuleKeyOptCtx *ctx, const void *value, size_t sample_size);
|
||||
typedef void (*moduleTypeFreeFunc2)(struct ValkeyModuleKeyOptCtx *ctx, void *value);
|
||||
typedef size_t (*moduleTypeFreeEffortFunc2)(struct ValkeyModuleKeyOptCtx *ctx, const void *value);
|
||||
typedef void (*moduleTypeUnlinkFunc2)(struct ValkeyModuleKeyOptCtx *ctx, void *value);
|
||||
typedef void *(*moduleTypeCopyFunc2)(struct ValkeyModuleKeyOptCtx *ctx, const void *value);
|
||||
typedef int (*moduleTypeAuthCallback)(struct ValkeyModuleCtx *ctx, void *username, void *password, const char **err);
|
||||
|
||||
|
||||
/* The module type, which is referenced in each value of a given type, defines
|
||||
* the methods and links to the module exporting the type. */
|
||||
typedef struct RedisModuleType {
|
||||
typedef struct ValkeyModuleType {
|
||||
uint64_t id; /* Higher 54 bits of type ID + 10 lower bits of encoding ver. */
|
||||
struct RedisModule *module;
|
||||
struct ValkeyModule *module;
|
||||
moduleTypeLoadFunc rdb_load;
|
||||
moduleTypeSaveFunc rdb_save;
|
||||
moduleTypeRewriteFunc aof_rewrite;
|
||||
@ -813,7 +813,7 @@ typedef struct moduleValue {
|
||||
} moduleValue;
|
||||
|
||||
/* This structure represents a module inside the system. */
|
||||
struct RedisModule {
|
||||
struct ValkeyModule {
|
||||
void *handle; /* Module dlopen() handle. */
|
||||
char *name; /* Module name. */
|
||||
int ver; /* Module version. We use just progressive integers. */
|
||||
@ -827,25 +827,25 @@ struct RedisModule {
|
||||
int in_call; /* RM_Call() nesting level */
|
||||
int in_hook; /* Hooks callback nesting level for this module (0 or 1). */
|
||||
int options; /* Module options and capabilities. */
|
||||
int blocked_clients; /* Count of RedisModuleBlockedClient in this module. */
|
||||
RedisModuleInfoFunc info_cb; /* Callback for module to add INFO fields. */
|
||||
RedisModuleDefragFunc defrag_cb; /* Callback for global data defrag. */
|
||||
int blocked_clients; /* Count of ValkeyModuleBlockedClient in this module. */
|
||||
ValkeyModuleInfoFunc info_cb; /* Callback for module to add INFO fields. */
|
||||
ValkeyModuleDefragFunc defrag_cb; /* Callback for global data defrag. */
|
||||
struct moduleLoadQueueEntry *loadmod; /* Module load arguments for config rewrite. */
|
||||
int num_commands_with_acl_categories; /* Number of commands in this module included in acl categories */
|
||||
int onload; /* Flag to identify if the call is being made from Onload (0 or 1) */
|
||||
size_t num_acl_categories_added; /* Number of acl categories added by this module. */
|
||||
};
|
||||
typedef struct RedisModule RedisModule;
|
||||
typedef struct ValkeyModule ValkeyModule;
|
||||
|
||||
/* This is a wrapper for the 'rio' streams used inside rdb.c in Redis, so that
|
||||
* the user does not have to take the total count of the written bytes nor
|
||||
* to care about error conditions. */
|
||||
struct RedisModuleIO {
|
||||
struct ValkeyModuleIO {
|
||||
size_t bytes; /* Bytes read / written so far. */
|
||||
rio *rio; /* Rio stream. */
|
||||
moduleType *type; /* Module type doing the operation. */
|
||||
int error; /* True if error condition happened. */
|
||||
struct RedisModuleCtx *ctx; /* Optional context, see RM_GetContextFromIO()*/
|
||||
struct ValkeyModuleCtx *ctx; /* Optional context, see RM_GetContextFromIO()*/
|
||||
struct serverObject *key; /* Optional name of key processed */
|
||||
int dbid; /* The dbid of the key being processed, -1 when unknown. */
|
||||
sds pre_flush_buffer; /* A buffer that should be flushed before next write operation
|
||||
@ -870,7 +870,7 @@ struct RedisModuleIO {
|
||||
* a data structure, so that a digest can be created in a way that correctly
|
||||
* reflects the values. See the DEBUG DIGEST command implementation for more
|
||||
* background. */
|
||||
struct RedisModuleDigest {
|
||||
struct ValkeyModuleDigest {
|
||||
unsigned char o[20]; /* Ordered elements. */
|
||||
unsigned char x[20]; /* Xored elements. */
|
||||
struct serverObject *key; /* Optional name of key processed */
|
||||
@ -1041,11 +1041,11 @@ typedef struct blockingState {
|
||||
long long reploffset; /* Replication offset to reach. */
|
||||
|
||||
/* BLOCKED_MODULE */
|
||||
void *module_blocked_handle; /* RedisModuleBlockedClient structure.
|
||||
void *module_blocked_handle; /* ValkeyModuleBlockedClient structure.
|
||||
which is opaque for the Redis core, only
|
||||
handled in module.c. */
|
||||
|
||||
void *async_rm_call_handle; /* RedisModuleAsyncRMCallPromise structure.
|
||||
void *async_rm_call_handle; /* ValkeyModuleAsyncRMCallPromise structure.
|
||||
which is opaque for the Redis core, only
|
||||
handled in module.c. */
|
||||
} blockingState;
|
||||
@ -1232,13 +1232,13 @@ typedef struct client {
|
||||
listNode *client_list_node; /* list node in client list */
|
||||
listNode *postponed_list_node; /* list node within the postponed list */
|
||||
listNode *pending_read_list_node; /* list node in clients pending read list */
|
||||
void *module_blocked_client; /* Pointer to the RedisModuleBlockedClient associated with this
|
||||
void *module_blocked_client; /* Pointer to the ValkeyModuleBlockedClient associated with this
|
||||
* client. This is set in case of module authentication before the
|
||||
* unblocked client is reprocessed to handle reply callbacks. */
|
||||
void *module_auth_ctx; /* Ongoing / attempted module based auth callback's ctx.
|
||||
* This is only tracked within the context of the command attempting
|
||||
* authentication. If not NULL, it means module auth is in progress. */
|
||||
RedisModuleUserChangedFunc auth_callback; /* Module callback to execute
|
||||
ValkeyModuleUserChangedFunc auth_callback; /* Module callback to execute
|
||||
* when the authenticated user
|
||||
* changes. */
|
||||
void *auth_callback_privdata; /* Private data that is passed when the auth
|
||||
@ -2014,7 +2014,7 @@ struct valkeyServer {
|
||||
int cluster_module_flags; /* Set of flags that Redis modules are able
|
||||
to set in order to suppress certain
|
||||
native Redis Cluster features. Check the
|
||||
REDISMODULE_CLUSTER_FLAG_*. */
|
||||
VALKEYMODULE_CLUSTER_FLAG_*. */
|
||||
int cluster_allow_reads_when_down; /* Are reads allowed when the cluster
|
||||
is down? */
|
||||
int cluster_config_file_lock_fd; /* cluster config fd, will be flocked. */
|
||||
@ -2113,7 +2113,7 @@ typedef struct {
|
||||
* 2. keynum: there's an arg that contains the number of key args somewhere before the keys themselves
|
||||
*/
|
||||
|
||||
/* WARNING! Must be synced with generate-command-code.py and RedisModuleKeySpecBeginSearchType */
|
||||
/* WARNING! Must be synced with generate-command-code.py and ValkeyModuleKeySpecBeginSearchType */
|
||||
typedef enum {
|
||||
KSPEC_BS_INVALID = 0, /* Must be 0 */
|
||||
KSPEC_BS_UNKNOWN,
|
||||
@ -2121,7 +2121,7 @@ typedef enum {
|
||||
KSPEC_BS_KEYWORD
|
||||
} kspec_bs_type;
|
||||
|
||||
/* WARNING! Must be synced with generate-command-code.py and RedisModuleKeySpecFindKeysType */
|
||||
/* WARNING! Must be synced with generate-command-code.py and ValkeyModuleKeySpecFindKeysType */
|
||||
typedef enum {
|
||||
KSPEC_FK_INVALID = 0, /* Must be 0 */
|
||||
KSPEC_FK_UNKNOWN,
|
||||
@ -2129,7 +2129,7 @@ typedef enum {
|
||||
KSPEC_FK_KEYNUM
|
||||
} kspec_fk_type;
|
||||
|
||||
/* WARNING! This struct must match RedisModuleCommandKeySpec */
|
||||
/* WARNING! This struct must match ValkeyModuleCommandKeySpec */
|
||||
typedef struct {
|
||||
/* Declarative data */
|
||||
const char *notes;
|
||||
@ -2209,7 +2209,7 @@ typedef struct jsonObject {
|
||||
|
||||
#endif
|
||||
|
||||
/* WARNING! This struct must match RedisModuleCommandHistoryEntry */
|
||||
/* WARNING! This struct must match ValkeyModuleCommandHistoryEntry */
|
||||
typedef struct {
|
||||
const char *since;
|
||||
const char *changes;
|
||||
@ -2383,7 +2383,7 @@ struct serverCommand {
|
||||
dict *subcommands_dict; /* A dictionary that holds the subcommands, the key is the subcommand sds name
|
||||
* (not the fullname), and the value is the serverCommand structure pointer. */
|
||||
struct serverCommand *parent;
|
||||
struct RedisModuleCommand *module_cmd; /* A pointer to the module command data (NULL if native command) */
|
||||
struct ValkeyModuleCommand *module_cmd; /* A pointer to the module command data (NULL if native command) */
|
||||
};
|
||||
|
||||
struct serverError {
|
||||
@ -2505,7 +2505,7 @@ moduleType *moduleTypeLookupModuleByNameIgnoreCase(const char *name);
|
||||
void moduleTypeNameByID(char *name, uint64_t moduleid);
|
||||
const char *moduleTypeModuleName(moduleType *mt);
|
||||
const char *moduleNameFromCommand(struct serverCommand *cmd);
|
||||
void moduleFreeContext(struct RedisModuleCtx *ctx);
|
||||
void moduleFreeContext(struct ValkeyModuleCtx *ctx);
|
||||
void moduleCallCommandUnblockedHandler(client *c);
|
||||
int isModuleClientUnblocked(client *c);
|
||||
void unblockClientFromModule(client *c);
|
||||
|
24
src/tls.c
24
src/tls.c
@ -27,7 +27,7 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define REDISMODULE_CORE_MODULE /* A module that's part of the redis core, uses server.h too. */
|
||||
#define VALKEYMODULE_CORE_MODULE /* A module that's part of the redis core, uses server.h too. */
|
||||
|
||||
#include "server.h"
|
||||
#include "connhelpers.h"
|
||||
@ -1171,36 +1171,36 @@ int RedisRegisterConnectionTypeTLS(void) {
|
||||
|
||||
#include "release.h"
|
||||
|
||||
int RedisModule_OnLoad(void *ctx, RedisModuleString **argv, int argc) {
|
||||
int ValkeyModule_OnLoad(void *ctx, ValkeyModuleString **argv, int argc) {
|
||||
UNUSED(argv);
|
||||
UNUSED(argc);
|
||||
|
||||
/* Connection modules must be part of the same build as redis. */
|
||||
if (strcmp(REDIS_BUILD_ID_RAW, serverBuildIdRaw())) {
|
||||
serverLog(LL_NOTICE, "Connection type %s was not built together with the redis-server used.", CONN_TYPE_TLS);
|
||||
return REDISMODULE_ERR;
|
||||
return VALKEYMODULE_ERR;
|
||||
}
|
||||
|
||||
if (RedisModule_Init(ctx,"tls",1,REDISMODULE_APIVER_1) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
if (ValkeyModule_Init(ctx,"tls",1,VALKEYMODULE_APIVER_1) == VALKEYMODULE_ERR)
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
/* Connection modules is available only bootup. */
|
||||
if ((RedisModule_GetContextFlags(ctx) & REDISMODULE_CTX_FLAGS_SERVER_STARTUP) == 0) {
|
||||
if ((ValkeyModule_GetContextFlags(ctx) & VALKEYMODULE_CTX_FLAGS_SERVER_STARTUP) == 0) {
|
||||
serverLog(LL_NOTICE, "Connection type %s can be loaded only during bootup", CONN_TYPE_TLS);
|
||||
return REDISMODULE_ERR;
|
||||
return VALKEYMODULE_ERR;
|
||||
}
|
||||
|
||||
RedisModule_SetModuleOptions(ctx, REDISMODULE_OPTIONS_HANDLE_REPL_ASYNC_LOAD);
|
||||
ValkeyModule_SetModuleOptions(ctx, VALKEYMODULE_OPTIONS_HANDLE_REPL_ASYNC_LOAD);
|
||||
|
||||
if(connTypeRegister(&CT_TLS) != C_OK)
|
||||
return REDISMODULE_ERR;
|
||||
return VALKEYMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
return VALKEYMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_OnUnload(void *arg) {
|
||||
int ValkeyModule_OnUnload(void *arg) {
|
||||
UNUSED(arg);
|
||||
serverLog(LL_NOTICE, "Connection type %s can not be unloaded", CONN_TYPE_TLS);
|
||||
return REDISMODULE_ERR;
|
||||
return VALKEYMODULE_ERR;
|
||||
}
|
||||
#endif
|
||||
|
1698
src/valkeymodule.h
Normal file
1698
src/valkeymodule.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user