From b72579cc94b7b43af916574618e3951f15647a65 Mon Sep 17 00:00:00 2001 From: Victor Polevoy Date: Mon, 25 Nov 2024 14:55:57 +0100 Subject: [PATCH] Update the headers to the latest state. --- build.rs | 7 ++ redismodule-rs-macros-internals/src/lib.rs | 2 +- src/include/redismodule-rlec.h | 97 ++++++++++++++++++++++ src/include/redismodule.h | 95 ++++++++++++++------- src/lib.rs | 5 -- src/raw.rs | 2 - src/redismodule.c | 4 - 7 files changed, 172 insertions(+), 40 deletions(-) create mode 100644 src/include/redismodule-rlec.h diff --git a/build.rs b/build.rs index 707d99ad..2bbe2013 100644 --- a/build.rs +++ b/build.rs @@ -42,11 +42,15 @@ fn main() { // tricks that we need to complete the build. const EXPERIMENTAL_API: &str = "REDISMODULE_EXPERIMENTAL_API"; + const RLEC_API: &str = "REDISMODULE_RLEC"; + const REDISMODULE_MAIN: &str = "REDISMODULE_MAIN"; let mut build = cc::Build::new(); build .define(EXPERIMENTAL_API, None) + .define(RLEC_API, None) + .define(REDISMODULE_MAIN, None) .file("src/redismodule.c") .include("src/include/") .compile("redismodule"); @@ -55,7 +59,10 @@ fn main() { let bindings = bindings_generator .clang_arg(format!("-D{EXPERIMENTAL_API}")) + .clang_arg(format!("-D{RLEC_API}")) + .clang_arg(format!("-D{REDISMODULE_MAIN}")) .header("src/include/redismodule.h") + .header("src/include/redismodule-rlec.h") .allowlist_var("(REDIS|Redis).*") .blocklist_type("__darwin_.*") .allowlist_type("RedisModule.*") diff --git a/redismodule-rs-macros-internals/src/lib.rs b/redismodule-rs-macros-internals/src/lib.rs index befb6833..2caf3396 100644 --- a/redismodule-rs-macros-internals/src/lib.rs +++ b/redismodule-rs-macros-internals/src/lib.rs @@ -143,7 +143,7 @@ pub fn api(item: TokenStream) -> TokenStream { } else if #[cfg(any(#(#all_upper_features, )*))] { #new_ver_func } else { - compile_error!("min-redis-compatibility-version is not set correctly") + compile_error!("Cannot generate the api! macro code. The \"min-redis-compatibility-version\" feature is not set up correctly") } } }; diff --git a/src/include/redismodule-rlec.h b/src/include/redismodule-rlec.h new file mode 100644 index 00000000..44657d68 --- /dev/null +++ b/src/include/redismodule-rlec.h @@ -0,0 +1,97 @@ + +#pragma once + +// clang-format off + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//--------------------------------------------------------------------------------------------- +// bigredis extensions + +#define REDISMODULE_METADATA_NOT_ON_SWAP 0x80 + +/* Notification that a key's value is added to ram (from swap or otherwise). + * swap_key_flags has 4 bits that the module can write / read. + * when swap_key_metadata is NOT_ON_SWAP, it means the key is not loaded from swap. */ +typedef void (*RedisModuleTypeKeyAddedToDbDictFunc)(RedisModuleCtx *ctx, RedisModuleString *key, void *value, int swap_key_metadata); + +/* Notification that a key's value is removed from ram (may still exist on swap). + * when swap_key_metadata is NOT_ON_SWAP it means the key does not exist on swap. + * return swap_key_metadata or NOT_ON_SWAP if key is to be deleted (and not to be written). */ +typedef int (*RedisModuleTypeRemovingKeyFromDbDictFunc)(RedisModuleCtx *ctx, RedisModuleString *key, void *value, int swap_key_metadata, int writing_to_swap); + +/* return swap_key_metadata, 0 indicates nothing to write. when out_min_expire is -1 it indicates nothing to write. */ +typedef int (*RedisModuleTypeGetKeyMetadataForRdbFunc)(RedisModuleCtx *ctx, RedisModuleString *key, void *value, long long *out_min_expire, long long *out_max_expire); + +#define REDISMODULE_TYPE_EXT_METHOD_VERSION 1 +typedef struct RedisModuleTypeExtMethods { + uint64_t version; + RedisModuleTypeKeyAddedToDbDictFunc key_added_to_db_dict; + RedisModuleTypeRemovingKeyFromDbDictFunc removing_key_from_db_dict; + RedisModuleTypeGetKeyMetadataForRdbFunc get_key_metadata_for_rdb; +} RedisModuleTypeExtMethods; + +typedef void (*RedisModuleSwapPrefetchCB)(RedisModuleCtx *ctx, RedisModuleString *key, void* user_data); + +/* APIs */ + +REDISMODULE_API int (*RedisModule_SetDataTypeExtensions)(RedisModuleCtx *ctx, RedisModuleType *mt, RedisModuleTypeExtMethods *typemethods) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_SwapPrefetchKey)(RedisModuleCtx *ctx, RedisModuleString *keyname, RedisModuleSwapPrefetchCB fn, void *user_data, int flags) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetSwapKeyMetadata)(RedisModuleCtx *ctx, RedisModuleString *key) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_SetSwapKeyMetadata)(RedisModuleCtx *ctx, RedisModuleString *key, int module_metadata) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_IsKeyInRam)(RedisModuleCtx *ctx, RedisModuleString *key) REDISMODULE_ATTR; + +//--------------------------------------------------------------------------------------------- + +/* Keyspace changes notification classes. Every class is associated with a + * character for configuration purposes. + * NOTE: These have to be in sync with NOTIFY_* in server.h */ + +#define REDISMODULE_NOTIFY_TRIMMED (1<<30) /* trimmed by reshard trimming enterprise only event */ + +/* Server events definitions. + * Those flags should not be used directly by the module, instead + * the module should use RedisModuleEvent_* variables */ + +#define REDISMODULE_EVENT_SHARDING 1000 + +static const RedisModuleEvent + RedisModuleEvent_Sharding = { + REDISMODULE_EVENT_SHARDING, + 1 + }; + +/* Those are values that are used for the 'subevent' callback argument. */ + +#define REDISMODULE_SUBEVENT_SHARDING_SLOT_RANGE_CHANGED 0 +#define REDISMODULE_SUBEVENT_SHARDING_TRIMMING_STARTED 1 +#define REDISMODULE_SUBEVENT_SHARDING_TRIMMING_ENDED 2 + +/* APIs */ + +REDISMODULE_API int (*RedisModule_ShardingGetKeySlot)(RedisModuleString *keyname) REDISMODULE_ATTR; +REDISMODULE_API void (*RedisModule_ShardingGetSlotRange)(int *first_slot, int *last_slot) REDISMODULE_ATTR; + +//--------------------------------------------------------------------------------------------- + +#define REDISMODULE_RLEC_API_DEFS \ + REDISMODULE_GET_API(ShardingGetKeySlot); \ + REDISMODULE_GET_API(ShardingGetSlotRange); \ + REDISMODULE_GET_API(SetDataTypeExtensions); \ + REDISMODULE_GET_API(SwapPrefetchKey); \ + REDISMODULE_GET_API(GetSwapKeyMetadata); \ + REDISMODULE_GET_API(SetSwapKeyMetadata); \ + REDISMODULE_GET_API(IsKeyInRam); \ + /**/ + +//--------------------------------------------------------------------------------------------- + +#ifdef __cplusplus +} +#endif diff --git a/src/include/redismodule.h b/src/include/redismodule.h index d0597755..883b69b1 100644 --- a/src/include/redismodule.h +++ b/src/include/redismodule.h @@ -1,11 +1,16 @@ #ifndef REDISMODULE_H #define REDISMODULE_H +// clang-format off + #include #include #include #include +#ifdef __cplusplus +extern "C" { +#endif typedef struct RedisModuleString RedisModuleString; typedef struct RedisModuleKey RedisModuleKey; @@ -41,7 +46,7 @@ typedef long long ustime_t; /* API versions. */ #define REDISMODULE_APIVER_1 1 -/* Version of the RedisModuleTypeMethods structure. Once the RedisModuleTypeMethods +/* Version of the RedisModuleTypeMethods structure. Once the RedisModuleTypeMethods * structure is changed, this version number needs to be changed synchronistically. */ #define REDISMODULE_TYPE_METHOD_VERSION 5 @@ -227,8 +232,6 @@ This flag should not be used directly by the module. #define REDISMODULE_NOTIFY_LOADED (1<<12) /* module only key space notification, indicate a key loaded from rdb */ #define REDISMODULE_NOTIFY_MODULE (1<<13) /* d, module key space notification */ #define REDISMODULE_NOTIFY_NEW (1<<14) /* n, new key notification */ -/* RL Extension: */ -#define REDISMODULE_NOTIFY_TRIMMED (1<<30) /* trimmed by reshard trimming */ /* Next notification flag, must be updated when adding new flags above! This flag should not be used directly by the module. @@ -589,7 +592,7 @@ static const RedisModuleEvent /* Deprecated since Redis 7.0, not used anymore. */ __attribute__ ((deprecated)) RedisModuleEvent_ReplBackup = { - REDISMODULE_EVENT_REPL_BACKUP, + REDISMODULE_EVENT_REPL_BACKUP, 1 }, RedisModuleEvent_ReplAsyncLoad = { @@ -883,6 +886,7 @@ typedef struct RedisModuleServerInfoData RedisModuleServerInfoData; typedef struct RedisModuleScanCursor RedisModuleScanCursor; typedef struct RedisModuleUser RedisModuleUser; typedef struct RedisModuleKeyOptCtx RedisModuleKeyOptCtx; +typedef struct RedisModuleRdbStream RedisModuleRdbStream; typedef int (*RedisModuleCmdFunc)(RedisModuleCtx *ctx, RedisModuleString **argv, int argc); typedef void (*RedisModuleDisconnectFunc)(RedisModuleCtx *ctx, RedisModuleBlockedClient *bc); @@ -948,6 +952,10 @@ typedef struct RedisModuleTypeMethods { RedisModule_GetApi("RedisModule_" #name, ((void **)&RedisModule_ ## name)) /* Default API declaration prefix (not 'extern' for backwards compatibility) */ +#ifndef REDISMODULE_MAIN +#define REDISMODULE_API extern +#endif + #ifndef REDISMODULE_API #define REDISMODULE_API #endif @@ -960,8 +968,10 @@ typedef struct RedisModuleTypeMethods { REDISMODULE_API void * (*RedisModule_Alloc)(size_t bytes) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_TryAlloc)(size_t bytes) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_Realloc)(void *ptr, size_t bytes) REDISMODULE_ATTR; +REDISMODULE_API void * (*RedisModule_TryRealloc)(void *ptr, size_t bytes) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_Free)(void *ptr) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_Calloc)(size_t nmemb, size_t size) REDISMODULE_ATTR; +REDISMODULE_API void * (*RedisModule_TryCalloc)(size_t nmemb, size_t size) REDISMODULE_ATTR; REDISMODULE_API char * (*RedisModule_Strdup)(const char *str) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_GetApi)(const char *, void *) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_CreateCommand)(RedisModuleCtx *ctx, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep) REDISMODULE_ATTR; @@ -978,7 +988,7 @@ REDISMODULE_API int (*RedisModule_GetSelectedDb)(RedisModuleCtx *ctx) REDISMODUL REDISMODULE_API int (*RedisModule_SelectDb)(RedisModuleCtx *ctx, int newid) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_KeyExists)(RedisModuleCtx *ctx, RedisModuleString *keyname) REDISMODULE_ATTR; REDISMODULE_API RedisModuleKey * (*RedisModule_OpenKey)(RedisModuleCtx *ctx, RedisModuleString *keyname, int mode) REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetOpenKeyModesAll)() REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetOpenKeyModesAll)(void) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_CloseKey)(RedisModuleKey *kp) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_KeyType)(RedisModuleKey *kp) REDISMODULE_ATTR; REDISMODULE_API size_t (*RedisModule_ValueLength)(RedisModuleKey *kp) REDISMODULE_ATTR; @@ -1009,13 +1019,14 @@ REDISMODULE_API RedisModuleString * (*RedisModule_CreateString)(RedisModuleCtx * REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromLongLong)(RedisModuleCtx *ctx, long long ll) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromULongLong)(RedisModuleCtx *ctx, unsigned long long ull) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromDouble)(RedisModuleCtx *ctx, double d) REDISMODULE_ATTR; -// REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromLongDouble)(RedisModuleCtx *ctx, long double ld, int humanfriendly) REDISMODULE_ATTR; +REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromLongDouble)(RedisModuleCtx *ctx, long double ld, int humanfriendly) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromString)(RedisModuleCtx *ctx, const RedisModuleString *str) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringFromStreamID)(RedisModuleCtx *ctx, const RedisModuleStreamID *id) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_CreateStringPrintf)(RedisModuleCtx *ctx, const char *fmt, ...) REDISMODULE_ATTR_PRINTF(2,3) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_FreeString)(RedisModuleCtx *ctx, RedisModuleString *str) REDISMODULE_ATTR; REDISMODULE_API const char * (*RedisModule_StringPtrLen)(const RedisModuleString *str, size_t *len) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithError)(RedisModuleCtx *ctx, const char *err) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_ReplyWithErrorFormat)(RedisModuleCtx *ctx, const char *fmt, ...) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithSimpleString)(RedisModuleCtx *ctx, const char *msg) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithArray)(RedisModuleCtx *ctx, long len) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithMap)(RedisModuleCtx *ctx, long len) REDISMODULE_ATTR; @@ -1036,14 +1047,14 @@ REDISMODULE_API int (*RedisModule_ReplyWithVerbatimString)(RedisModuleCtx *ctx, REDISMODULE_API int (*RedisModule_ReplyWithVerbatimStringType)(RedisModuleCtx *ctx, const char *buf, size_t len, const char *ext) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithNull)(RedisModuleCtx *ctx) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithBool)(RedisModuleCtx *ctx, int b) REDISMODULE_ATTR; -// REDISMODULE_API int (*RedisModule_ReplyWithLongDouble)(RedisModuleCtx *ctx, long double d) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_ReplyWithLongDouble)(RedisModuleCtx *ctx, long double d) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithDouble)(RedisModuleCtx *ctx, double d) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithBigNumber)(RedisModuleCtx *ctx, const char *bignum, size_t len) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ReplyWithCallReply)(RedisModuleCtx *ctx, RedisModuleCallReply *reply) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_StringToLongLong)(const RedisModuleString *str, long long *ll) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_StringToULongLong)(const RedisModuleString *str, unsigned long long *ull) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_StringToDouble)(const RedisModuleString *str, double *d) REDISMODULE_ATTR; -// REDISMODULE_API int (*RedisModule_StringToLongDouble)(const RedisModuleString *str, long double *d) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_StringToLongDouble)(const RedisModuleString *str, long double *d) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_StringToStreamID)(const RedisModuleString *str, RedisModuleStreamID *id) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_AutoMemory)(RedisModuleCtx *ctx) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_Replicate)(RedisModuleCtx *ctx, const char *cmdname, const char *fmt, ...) REDISMODULE_ATTR; @@ -1099,7 +1110,7 @@ REDISMODULE_API int (*RedisModule_SetClientNameById)(uint64_t id, RedisModuleStr REDISMODULE_API int (*RedisModule_PublishMessage)(RedisModuleCtx *ctx, RedisModuleString *channel, RedisModuleString *message) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_PublishMessageShard)(RedisModuleCtx *ctx, RedisModuleString *channel, RedisModuleString *message) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_GetContextFlags)(RedisModuleCtx *ctx) REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_AvoidReplicaTraffic)() REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_AvoidReplicaTraffic)(void) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_PoolAlloc)(RedisModuleCtx *ctx, size_t bytes) REDISMODULE_ATTR; REDISMODULE_API RedisModuleType * (*RedisModule_CreateDataType)(RedisModuleCtx *ctx, const char *name, int encver, RedisModuleTypeMethods *typemethods) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ModuleTypeSetValue)(RedisModuleKey *key, RedisModuleType *mt, void *value) REDISMODULE_ATTR; @@ -1122,8 +1133,8 @@ REDISMODULE_API void (*RedisModule_SaveDouble)(RedisModuleIO *io, double value) REDISMODULE_API double (*RedisModule_LoadDouble)(RedisModuleIO *io) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_SaveFloat)(RedisModuleIO *io, float value) REDISMODULE_ATTR; REDISMODULE_API float (*RedisModule_LoadFloat)(RedisModuleIO *io) REDISMODULE_ATTR; -// REDISMODULE_API void (*RedisModule_SaveLongDouble)(RedisModuleIO *io, long double value) REDISMODULE_ATTR; -// REDISMODULE_API long double (*RedisModule_LoadLongDouble)(RedisModuleIO *io) REDISMODULE_ATTR; +REDISMODULE_API void (*RedisModule_SaveLongDouble)(RedisModuleIO *io, long double value) REDISMODULE_ATTR; +REDISMODULE_API long double (*RedisModule_LoadLongDouble)(RedisModuleIO *io) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_LoadDataTypeFromString)(const RedisModuleString *str, const RedisModuleType *mt) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_LoadDataTypeFromStringEncver)(const RedisModuleString *str, const RedisModuleType *mt, int encver) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_SaveDataTypeToString)(RedisModuleCtx *ctx, void *data, const RedisModuleType *mt) REDISMODULE_ATTR; @@ -1202,17 +1213,17 @@ REDISMODULE_API RedisModuleBlockedClient * (*RedisModule_BlockClientOnKeys)(Redi REDISMODULE_API RedisModuleBlockedClient * (*RedisModule_BlockClientOnKeysWithFlags)(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms, RedisModuleString **keys, int numkeys, void *privdata, int flags) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_SignalKeyAsReady)(RedisModuleCtx *ctx, RedisModuleString *key) REDISMODULE_ATTR; REDISMODULE_API RedisModuleString * (*RedisModule_GetBlockedClientReadyKey)(RedisModuleCtx *ctx) REDISMODULE_ATTR; -REDISMODULE_API RedisModuleScanCursor * (*RedisModule_ScanCursorCreate)() REDISMODULE_ATTR; +REDISMODULE_API RedisModuleScanCursor * (*RedisModule_ScanCursorCreate)(void) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_ScanCursorRestart)(RedisModuleScanCursor *cursor) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_ScanCursorDestroy)(RedisModuleScanCursor *cursor) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_Scan)(RedisModuleCtx *ctx, RedisModuleScanCursor *cursor, RedisModuleScanCB fn, void *privdata) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ScanKey)(RedisModuleKey *key, RedisModuleScanCursor *cursor, RedisModuleScanKeyCB fn, void *privdata) REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetContextFlagsAll)() REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetModuleOptionsAll)() REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetKeyspaceNotificationFlagsAll)() REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetContextFlagsAll)(void) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetModuleOptionsAll)(void) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetKeyspaceNotificationFlagsAll)(void) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_IsSubEventSupported)(RedisModuleEvent event, uint64_t subevent) REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetServerVersion)() REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetTypeMethodVersion)() REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetServerVersion)(void) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetTypeMethodVersion)(void) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_Yield)(RedisModuleCtx *ctx, int flags, const char *busy_reply) REDISMODULE_ATTR; REDISMODULE_API RedisModuleBlockedClient * (*RedisModule_BlockClient)(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(RedisModuleCtx*,void*), long long timeout_ms) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_BlockClientGetPrivateData)(RedisModuleBlockedClient *blocked_client) REDISMODULE_ATTR; @@ -1235,7 +1246,7 @@ REDISMODULE_API void (*RedisModule_ThreadSafeContextUnlock)(RedisModuleCtx *ctx) REDISMODULE_API int (*RedisModule_SubscribeToKeyspaceEvents)(RedisModuleCtx *ctx, int types, RedisModuleNotificationFunc cb) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_AddPostNotificationJob)(RedisModuleCtx *ctx, RedisModulePostNotificationJobFunc callback, void *pd, void (*free_pd)(void*)) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_NotifyKeyspaceEvent)(RedisModuleCtx *ctx, int type, const char *event, RedisModuleString *key) REDISMODULE_ATTR; -REDISMODULE_API int (*RedisModule_GetNotifyKeyspaceEvents)() REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_GetNotifyKeyspaceEvents)(void) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_BlockedClientDisconnected)(RedisModuleCtx *ctx) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_RegisterClusterMessageReceiver)(RedisModuleCtx *ctx, uint8_t type, RedisModuleClusterMessageReceiver callback) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_SendClusterMessage)(RedisModuleCtx *ctx, const char *target_id, uint8_t type, const char *msg, uint32_t len) REDISMODULE_ATTR; @@ -1251,6 +1262,8 @@ REDISMODULE_API void (*RedisModule_GetRandomBytes)(unsigned char *dst, size_t le REDISMODULE_API void (*RedisModule_GetRandomHexChars)(char *dst, size_t len) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_SetDisconnectCallback)(RedisModuleBlockedClient *bc, RedisModuleDisconnectFunc callback) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_SetClusterFlags)(RedisModuleCtx *ctx, uint64_t flags) REDISMODULE_ATTR; +REDISMODULE_API unsigned int (*RedisModule_ClusterKeySlot)(RedisModuleString *key) REDISMODULE_ATTR; +REDISMODULE_API const char *(*RedisModule_ClusterCanonicalKeyNameInSlot)(unsigned int slot) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ExportSharedAPI)(RedisModuleCtx *ctx, const char *apiname, void *func) REDISMODULE_ATTR; REDISMODULE_API void * (*RedisModule_GetSharedAPI)(RedisModuleCtx *ctx, const char *apiname) REDISMODULE_ATTR; REDISMODULE_API RedisModuleCommandFilter * (*RedisModule_RegisterCommandFilter)(RedisModuleCtx *ctx, RedisModuleCommandFilterFunc cb, int flags) REDISMODULE_ATTR; @@ -1260,11 +1273,12 @@ REDISMODULE_API RedisModuleString * (*RedisModule_CommandFilterArgGet)(RedisModu REDISMODULE_API int (*RedisModule_CommandFilterArgInsert)(RedisModuleCommandFilterCtx *fctx, int pos, RedisModuleString *arg) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_CommandFilterArgReplace)(RedisModuleCommandFilterCtx *fctx, int pos, RedisModuleString *arg) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_CommandFilterArgDelete)(RedisModuleCommandFilterCtx *fctx, int pos) REDISMODULE_ATTR; +REDISMODULE_API unsigned long long (*RedisModule_CommandFilterGetClientId)(RedisModuleCommandFilterCtx *fctx) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_Fork)(RedisModuleForkDoneHandler cb, void *user_data) REDISMODULE_ATTR; REDISMODULE_API void (*RedisModule_SendChildHeartbeat)(double progress) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_ExitFromChild)(int retcode) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_KillForkChild)(int child_pid) REDISMODULE_ATTR; -REDISMODULE_API float (*RedisModule_GetUsedMemoryRatio)() REDISMODULE_ATTR; +REDISMODULE_API float (*RedisModule_GetUsedMemoryRatio)(void) REDISMODULE_ATTR; REDISMODULE_API size_t (*RedisModule_MallocSize)(void* ptr) REDISMODULE_ATTR; REDISMODULE_API size_t (*RedisModule_MallocUsableSize)(void *ptr) REDISMODULE_ATTR; REDISMODULE_API size_t (*RedisModule_MallocSizeString)(RedisModuleString* str) REDISMODULE_ATTR; @@ -1307,19 +1321,29 @@ REDISMODULE_API int (*RedisModule_RegisterNumericConfig)(RedisModuleCtx *ctx, co REDISMODULE_API int (*RedisModule_RegisterStringConfig)(RedisModuleCtx *ctx, const char *name, const char *default_val, unsigned int flags, RedisModuleConfigGetStringFunc getfn, RedisModuleConfigSetStringFunc setfn, RedisModuleConfigApplyFunc applyfn, void *privdata) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_RegisterEnumConfig)(RedisModuleCtx *ctx, const char *name, int default_val, unsigned int flags, const char **enum_values, const int *int_values, int num_enum_vals, RedisModuleConfigGetEnumFunc getfn, RedisModuleConfigSetEnumFunc setfn, RedisModuleConfigApplyFunc applyfn, void *privdata) REDISMODULE_ATTR; REDISMODULE_API int (*RedisModule_LoadConfigs)(RedisModuleCtx *ctx) REDISMODULE_ATTR; +REDISMODULE_API RedisModuleRdbStream *(*RedisModule_RdbStreamCreateFromFile)(const char *filename) REDISMODULE_ATTR; +REDISMODULE_API void (*RedisModule_RdbStreamFree)(RedisModuleRdbStream *stream) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_RdbLoad)(RedisModuleCtx *ctx, RedisModuleRdbStream *stream, int flags) REDISMODULE_ATTR; +REDISMODULE_API int (*RedisModule_RdbSave)(RedisModuleCtx *ctx, RedisModuleRdbStream *stream, int flags) REDISMODULE_ATTR; #define RedisModule_IsAOFClient(id) ((id) == UINT64_MAX) +#ifdef REDISMODULE_SDK_RLEC +#include "redismodule-rlec.h" +#endif + /* This is included inline inside each Redis module. */ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) REDISMODULE_ATTR_UNUSED; -static void RedisModule_InitAPI(RedisModuleCtx *ctx) { +static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { void *getapifuncptr = ((void**)ctx)[0]; RedisModule_GetApi = (int (*)(const char *, void *)) (unsigned long)getapifuncptr; REDISMODULE_GET_API(Alloc); REDISMODULE_GET_API(TryAlloc); REDISMODULE_GET_API(Calloc); + REDISMODULE_GET_API(TryCalloc); REDISMODULE_GET_API(Free); REDISMODULE_GET_API(Realloc); + REDISMODULE_GET_API(TryRealloc); REDISMODULE_GET_API(Strdup); REDISMODULE_GET_API(CreateCommand); REDISMODULE_GET_API(GetCommand); @@ -1332,6 +1356,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(WrongArity); REDISMODULE_GET_API(ReplyWithLongLong); REDISMODULE_GET_API(ReplyWithError); + REDISMODULE_GET_API(ReplyWithErrorFormat); REDISMODULE_GET_API(ReplyWithSimpleString); REDISMODULE_GET_API(ReplyWithArray); REDISMODULE_GET_API(ReplyWithMap); @@ -1355,7 +1380,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(ReplyWithCallReply); REDISMODULE_GET_API(ReplyWithDouble); REDISMODULE_GET_API(ReplyWithBigNumber); - // REDISMODULE_GET_API(ReplyWithLongDouble); + REDISMODULE_GET_API(ReplyWithLongDouble); REDISMODULE_GET_API(GetSelectedDb); REDISMODULE_GET_API(SelectDb); REDISMODULE_GET_API(KeyExists); @@ -1373,7 +1398,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(StringToLongLong); REDISMODULE_GET_API(StringToULongLong); REDISMODULE_GET_API(StringToDouble); - // REDISMODULE_GET_API(StringToLongDouble); + REDISMODULE_GET_API(StringToLongDouble); REDISMODULE_GET_API(StringToStreamID); REDISMODULE_GET_API(Call); REDISMODULE_GET_API(CallReplyProto); @@ -1398,7 +1423,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(CreateStringFromLongLong); REDISMODULE_GET_API(CreateStringFromULongLong); REDISMODULE_GET_API(CreateStringFromDouble); - // REDISMODULE_GET_API(CreateStringFromLongDouble); + REDISMODULE_GET_API(CreateStringFromLongDouble); REDISMODULE_GET_API(CreateStringFromString); REDISMODULE_GET_API(CreateStringFromStreamID); REDISMODULE_GET_API(CreateStringPrintf); @@ -1473,8 +1498,8 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(LoadDouble); REDISMODULE_GET_API(SaveFloat); REDISMODULE_GET_API(LoadFloat); - // REDISMODULE_GET_API(SaveLongDouble); - // REDISMODULE_GET_API(LoadLongDouble); + REDISMODULE_GET_API(SaveLongDouble); + REDISMODULE_GET_API(LoadLongDouble); REDISMODULE_GET_API(SaveDataTypeToString); REDISMODULE_GET_API(LoadDataTypeFromString); REDISMODULE_GET_API(LoadDataTypeFromStringEncver); @@ -1608,6 +1633,8 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(GetRandomBytes); REDISMODULE_GET_API(GetRandomHexChars); REDISMODULE_GET_API(SetClusterFlags); + REDISMODULE_GET_API(ClusterKeySlot); + REDISMODULE_GET_API(ClusterCanonicalKeyNameInSlot); REDISMODULE_GET_API(ExportSharedAPI); REDISMODULE_GET_API(GetSharedAPI); REDISMODULE_GET_API(RegisterCommandFilter); @@ -1617,6 +1644,7 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(CommandFilterArgInsert); REDISMODULE_GET_API(CommandFilterArgReplace); REDISMODULE_GET_API(CommandFilterArgDelete); + REDISMODULE_GET_API(CommandFilterGetClientId); REDISMODULE_GET_API(Fork); REDISMODULE_GET_API(SendChildHeartbeat); REDISMODULE_GET_API(ExitFromChild); @@ -1664,10 +1692,16 @@ static void RedisModule_InitAPI(RedisModuleCtx *ctx) { REDISMODULE_GET_API(RegisterStringConfig); REDISMODULE_GET_API(RegisterEnumConfig); REDISMODULE_GET_API(LoadConfigs); -} + REDISMODULE_GET_API(RdbStreamCreateFromFile); + REDISMODULE_GET_API(RdbStreamFree); + REDISMODULE_GET_API(RdbLoad); + REDISMODULE_GET_API(RdbSave); + + +#ifdef REDISMODULE_RLEC_API_DEFS + REDISMODULE_RLEC_API_DEFS +#endif -static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { - RedisModule_InitAPI(ctx); if (RedisModule_IsModuleNameBusy && RedisModule_IsModuleNameBusy(name)) return REDISMODULE_ERR; RedisModule_SetModuleAttribs(ctx,name,ver,apiver); return REDISMODULE_OK; @@ -1678,4 +1712,9 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int #define RMAPI_FUNC_SUPPORTED(func) (func != NULL) #endif /* REDISMODULE_CORE */ + +#ifdef __cplusplus +} +#endif + #endif /* REDISMODULE_H */ diff --git a/src/lib.rs b/src/lib.rs index b4195b78..196cb268 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,11 +108,6 @@ pub fn basic_info_command_handler(ctx: &InfoContext, for_crash_report: bool) { .for_each(|e| log::error!("Couldn't build info for the module's custom handler: {e}")); } -/// Initialize RedisModuleAPI without register as a module. -pub fn init_api(ctx: &Context) { - unsafe { crate::raw::Export_RedisModule_InitAPI(ctx.ctx) }; -} - pub(crate) unsafe fn deallocate_pointer

(p: *mut P) { std::ptr::drop_in_place(p); std::alloc::dealloc(p as *mut u8, std::alloc::Layout::new::

()); diff --git a/src/raw.rs b/src/raw.rs index 10f992a9..1babbf5a 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -198,8 +198,6 @@ extern "C" { module_version: c_int, api_version: c_int, ) -> c_int; - - pub fn Export_RedisModule_InitAPI(ctx: *mut RedisModuleCtx) -> c_void; } /////////////////////////////////////////////////////////////// diff --git a/src/redismodule.c b/src/redismodule.c index 0f18162b..5e8afc49 100644 --- a/src/redismodule.c +++ b/src/redismodule.c @@ -7,7 +7,3 @@ int Export_RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int apiver) { return RedisModule_Init(ctx, name, ver, apiver); } - -void Export_RedisModule_InitAPI(RedisModuleCtx *ctx) { - RedisModule_InitAPI(ctx); -}