summaryrefslogtreecommitdiff
path: root/src/redismodule.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/redismodule.h')
-rw-r--r--src/redismodule.h179
1 files changed, 154 insertions, 25 deletions
diff --git a/src/redismodule.h b/src/redismodule.h
index 3255fcc30..79ce2c697 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -236,14 +236,16 @@ typedef uint64_t RedisModuleTimerID;
/* Declare that the module can handle errors with RedisModule_SetModuleOptions. */
#define REDISMODULE_OPTIONS_HANDLE_IO_ERRORS (1<<0)
-/* Declare that the module can handle diskless async replication with RedisModule_SetModuleOptions. */
-#define REDISMODULE_OPTIONS_HANDLE_REPL_ASYNC_LOAD (1<<1)
-
/* When set, Redis will not call RedisModule_SignalModifiedKey(), implicitly in
* RedisModule_CloseKey, and the module needs to do that when manually when keys
* are modified from the user's sperspective, to invalidate WATCH. */
#define REDISMODULE_OPTION_NO_IMPLICIT_SIGNAL_MODIFIED (1<<1)
+/* Declare that the module can handle diskless async replication with RedisModule_SetModuleOptions. */
+#define REDISMODULE_OPTIONS_HANDLE_REPL_ASYNC_LOAD (1<<2)
+
+/* Definitions for RedisModule_SetCommandInfo. */
+
typedef enum {
REDISMODULE_ARG_TYPE_STRING,
REDISMODULE_ARG_TYPE_INTEGER,
@@ -260,12 +262,146 @@ typedef enum {
#define REDISMODULE_CMD_ARG_OPTIONAL (1<<0) /* The argument is optional (like GET in SET command) */
#define REDISMODULE_CMD_ARG_MULTIPLE (1<<1) /* The argument may repeat itself (like key in DEL) */
#define REDISMODULE_CMD_ARG_MULTIPLE_TOKEN (1<<2) /* The argument may repeat itself, and so does its token (like `GET pattern` in SORT) */
+#define _REDISMODULE_CMD_ARG_NEXT (1<<3)
-/* Redis ACL key permission flags, which specify which permissions a module
- * needs on a key. */
-#define REDISMODULE_KEY_PERMISSION_READ (1<<0)
-#define REDISMODULE_KEY_PERMISSION_WRITE (1<<1)
-#define REDISMODULE_KEY_PERMISSION_ALL (REDISMODULE_KEY_PERMISSION_READ | REDISMODULE_KEY_PERMISSION_WRITE)
+typedef enum {
+ REDISMODULE_KSPEC_BS_INVALID = 0, /* Must be zero. An implicitly value of
+ * zero is provided when the field is
+ * absent in a struct literal. */
+ REDISMODULE_KSPEC_BS_UNKNOWN,
+ REDISMODULE_KSPEC_BS_INDEX,
+ REDISMODULE_KSPEC_BS_KEYWORD
+} RedisModuleKeySpecBeginSearchType;
+
+typedef enum {
+ REDISMODULE_KSPEC_FK_OMITTED = 0, /* Used when the field is absent in a
+ * struct literal. Don't use this value
+ * explicitly. */
+ REDISMODULE_KSPEC_FK_UNKNOWN,
+ REDISMODULE_KSPEC_FK_RANGE,
+ REDISMODULE_KSPEC_FK_KEYNUM
+} RedisModuleKeySpecFindKeysType;
+
+/* Key-spec flags. For details, see the documentation of
+ * RedisModule_SetCommandInfo and the key-spec flags in server.h. */
+#define REDISMODULE_CMD_KEY_RO (1ULL<<0)
+#define REDISMODULE_CMD_KEY_RW (1ULL<<1)
+#define REDISMODULE_CMD_KEY_OW (1ULL<<2)
+#define REDISMODULE_CMD_KEY_RM (1ULL<<3)
+#define REDISMODULE_CMD_KEY_ACCESS (1ULL<<4)
+#define REDISMODULE_CMD_KEY_UPDATE (1ULL<<5)
+#define REDISMODULE_CMD_KEY_INSERT (1ULL<<6)
+#define REDISMODULE_CMD_KEY_DELETE (1ULL<<7)
+#define REDISMODULE_CMD_KEY_NOT_KEY (1ULL<<8)
+#define REDISMODULE_CMD_KEY_INCOMPLETE (1ULL<<9)
+#define REDISMODULE_CMD_KEY_VARIABLE_FLAGS (1ULL<<10)
+
+/* Channel flags, for details see the documentation of
+ * RedisModule_ChannelAtPosWithFlags. */
+#define REDISMODULE_CMD_CHANNEL_PATTERN (1ULL<<0)
+#define REDISMODULE_CMD_CHANNEL_PUBLISH (1ULL<<1)
+#define REDISMODULE_CMD_CHANNEL_SUBSCRIBE (1ULL<<2)
+#define REDISMODULE_CMD_CHANNEL_UNSUBSCRIBE (1ULL<<3)
+
+typedef struct RedisModuleCommandArg {
+ const char *name;
+ RedisModuleCommandArgType type;
+ int key_spec_index; /* If type is KEY, this is a zero-based index of
+ * the key_spec in the command. For other types,
+ * you may specify -1. */
+ const char *token; /* If type is PURE_TOKEN, this is the token. */
+ const char *summary;
+ const char *since;
+ int flags; /* The REDISMODULE_CMD_ARG_* macros. */
+ struct RedisModuleCommandArg *subargs;
+} RedisModuleCommandArg;
+
+typedef struct {
+ const char *since;
+ const char *changes;
+} RedisModuleCommandHistoryEntry;
+
+typedef struct {
+ const char *notes;
+ uint64_t flags; /* REDISMODULE_CMD_KEY_* macros. */
+ RedisModuleKeySpecBeginSearchType begin_search_type;
+ union {
+ struct {
+ /* The index from which we start the search for keys */
+ int pos;
+ } index;
+ struct {
+ /* The keyword that indicates the beginning of key args */
+ const char *keyword;
+ /* An index in argv from which to start searching.
+ * Can be negative, which means start search from the end, in reverse
+ * (Example: -2 means to start in reverse from the panultimate arg) */
+ int startfrom;
+ } keyword;
+ } bs;
+ RedisModuleKeySpecFindKeysType find_keys_type;
+ union {
+ struct {
+ /* Index of the last key relative to the result of the begin search
+ * step. Can be negative, in which case it's not relative. -1
+ * indicating till the last argument, -2 one before the last and so
+ * on. */
+ int lastkey;
+ /* How many args should we skip after finding a key, in order to
+ * find the next one. */
+ int keystep;
+ /* If lastkey is -1, we use limit to stop the search by a factor. 0
+ * and 1 mean no limit. 2 means 1/2 of the remaining args, 3 means
+ * 1/3, and so on. */
+ int limit;
+ } range;
+ struct {
+ /* Index of the argument containing the number of keys to come
+ * relative to the result of the begin search step */
+ int keynumidx;
+ /* Index of the fist key. (Usually it's just after keynumidx, in
+ * which case it should be set to keynumidx + 1.) */
+ int firstkey;
+ /* How many args should we skip after finding a key, in order to
+ * find the next one, relative to the result of the begin search
+ * step. */
+ int keystep;
+ } keynum;
+ } fk;
+} RedisModuleCommandKeySpec;
+
+typedef struct {
+ int version;
+ size_t sizeof_historyentry;
+ size_t sizeof_keyspec;
+ size_t sizeof_arg;
+} RedisModuleCommandInfoVersion;
+
+static const RedisModuleCommandInfoVersion RedisModule_CurrentCommandInfoVersion = {
+ .version = 1,
+ .sizeof_historyentry = sizeof(RedisModuleCommandHistoryEntry),
+ .sizeof_keyspec = sizeof(RedisModuleCommandKeySpec),
+ .sizeof_arg = sizeof(RedisModuleCommandArg)
+};
+
+#define REDISMODULE_COMMAND_INFO_VERSION (&RedisModule_CurrentCommandInfoVersion)
+
+typedef struct {
+ /* Always set version to REDISMODULE_COMMAND_INFO_VERSION */
+ const RedisModuleCommandInfoVersion *version;
+ /* Version 1 fields (added in Redis 7.0.0) */
+ const char *summary; /* Summary of the command */
+ const char *complexity; /* Complexity description */
+ const char *since; /* Debut module version of the command */
+ RedisModuleCommandHistoryEntry *history; /* History */
+ /* A string of space-separated tips meant for clients/proxies regarding this
+ * command */
+ const char *tips;
+ /* Number of arguments, it is possible to use -N to say >= N */
+ int arity;
+ RedisModuleCommandKeySpec *key_specs;
+ RedisModuleCommandArg *args;
+} RedisModuleCommandInfo;
/* Eventloop definitions. */
#define REDISMODULE_EVENTLOOP_READABLE 1
@@ -623,7 +759,6 @@ typedef struct RedisModuleScanCursor RedisModuleScanCursor;
typedef struct RedisModuleDefragCtx RedisModuleDefragCtx;
typedef struct RedisModuleUser RedisModuleUser;
typedef struct RedisModuleKeyOptCtx RedisModuleKeyOptCtx;
-typedef struct RedisModuleCommandArg RedisModuleCommandArg;
typedef int (*RedisModuleCmdFunc)(RedisModuleCtx *ctx, RedisModuleString **argv, int argc);
typedef void (*RedisModuleDisconnectFunc)(RedisModuleCtx *ctx, RedisModuleBlockedClient *bc);
@@ -697,6 +832,7 @@ 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;
REDISMODULE_API RedisModuleCommand *(*RedisModule_GetCommand)(RedisModuleCtx *ctx, const char *name) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_CreateSubcommand)(RedisModuleCommand *parent, const char *name, RedisModuleCmdFunc cmdfunc, const char *strflags, int firstkey, int lastkey, int keystep) REDISMODULE_ATTR;
+REDISMODULE_API int (*RedisModule_SetCommandInfo)(RedisModuleCommand *command, const RedisModuleCommandInfo *info) REDISMODULE_ATTR;
REDISMODULE_API void (*RedisModule_SetModuleAttribs)(RedisModuleCtx *ctx, const char *name, int ver, int apiver) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_IsModuleNameBusy)(const char *name) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_WrongArity)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
@@ -810,6 +946,9 @@ REDISMODULE_API long long (*RedisModule_StreamTrimByLength)(RedisModuleKey *key,
REDISMODULE_API long long (*RedisModule_StreamTrimByID)(RedisModuleKey *key, int flags, RedisModuleStreamID *id) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
REDISMODULE_API void (*RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos) REDISMODULE_ATTR;
+REDISMODULE_API void (*RedisModule_KeyAtPosWithFlags)(RedisModuleCtx *ctx, int pos, int flags) REDISMODULE_ATTR;
+REDISMODULE_API int (*RedisModule_IsChannelsPositionRequest)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
+REDISMODULE_API void (*RedisModule_ChannelAtPosWithFlags)(RedisModuleCtx *ctx, int pos, int flags) REDISMODULE_ATTR;
REDISMODULE_API unsigned long long (*RedisModule_GetClientId)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
REDISMODULE_API RedisModuleString * (*RedisModule_GetClientUserNameById)(RedisModuleCtx *ctx, uint64_t id) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_GetClientInfoById)(void *ci, uint64_t id) REDISMODULE_ATTR;
@@ -924,14 +1063,6 @@ REDISMODULE_API int (*RedisModule_GetKeyspaceNotificationFlagsAll)() REDISMODULE
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;
-#ifdef INCLUDE_UNRELEASED_KEYSPEC_API
-REDISMODULE_API int (*RedisModule_AddCommandKeySpec)(RedisModuleCommand *command, const char *specflags, int *spec_id) REDISMODULE_ATTR;
-REDISMODULE_API int (*RedisModule_SetCommandKeySpecBeginSearchIndex)(RedisModuleCommand *command, int spec_id, int index) REDISMODULE_ATTR;
-REDISMODULE_API int (*RedisModule_SetCommandKeySpecBeginSearchKeyword)(RedisModuleCommand *command, int spec_id, const char *keyword, int startfrom) REDISMODULE_ATTR;
-REDISMODULE_API int (*RedisModule_SetCommandKeySpecFindKeysRange)(RedisModuleCommand *command, int spec_id, int lastkey, int keystep, int limit) REDISMODULE_ATTR;
-REDISMODULE_API int (*RedisModule_SetCommandKeySpecFindKeysKeynum)(RedisModuleCommand *command, int spec_id, int keynumidx, int firstkey, int keystep) REDISMODULE_ATTR;
-#endif
-
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 int (*RedisModule_UnblockClient)(RedisModuleBlockedClient *bc, void *privdata) REDISMODULE_ATTR;
@@ -995,6 +1126,7 @@ REDISMODULE_API int (*RedisModule_AuthenticateClientWithUser)(RedisModuleCtx *ct
REDISMODULE_API int (*RedisModule_DeauthenticateAndCloseClient)(RedisModuleCtx *ctx, uint64_t client_id) REDISMODULE_ATTR;
REDISMODULE_API RedisModuleString * (*RedisModule_GetClientCertificate)(RedisModuleCtx *ctx, uint64_t id) REDISMODULE_ATTR;
REDISMODULE_API int *(*RedisModule_GetCommandKeys)(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, int *num_keys) REDISMODULE_ATTR;
+REDISMODULE_API int *(*RedisModule_GetCommandKeysWithFlags)(RedisModuleCtx *ctx, RedisModuleString **argv, int argc, int *num_keys, int **out_flags) REDISMODULE_ATTR;
REDISMODULE_API const char *(*RedisModule_GetCurrentCommandName)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
REDISMODULE_API int (*RedisModule_RegisterDefragFunc)(RedisModuleCtx *ctx, RedisModuleDefragFunc func) REDISMODULE_ATTR;
REDISMODULE_API void *(*RedisModule_DefragAlloc)(RedisModuleDefragCtx *ctx, void *ptr) REDISMODULE_ATTR;
@@ -1023,6 +1155,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(CreateCommand);
REDISMODULE_GET_API(GetCommand);
REDISMODULE_GET_API(CreateSubcommand);
+ REDISMODULE_GET_API(SetCommandInfo);
REDISMODULE_GET_API(SetModuleAttribs);
REDISMODULE_GET_API(IsModuleNameBusy);
REDISMODULE_GET_API(WrongArity);
@@ -1136,6 +1269,9 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(StreamTrimByID);
REDISMODULE_GET_API(IsKeysPositionRequest);
REDISMODULE_GET_API(KeyAtPos);
+ REDISMODULE_GET_API(KeyAtPosWithFlags);
+ REDISMODULE_GET_API(IsChannelsPositionRequest);
+ REDISMODULE_GET_API(ChannelAtPosWithFlags);
REDISMODULE_GET_API(GetClientId);
REDISMODULE_GET_API(GetClientUserNameById);
REDISMODULE_GET_API(GetContextFlags);
@@ -1250,13 +1386,6 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(IsSubEventSupported);
REDISMODULE_GET_API(GetServerVersion);
REDISMODULE_GET_API(GetTypeMethodVersion);
-#ifdef INCLUDE_UNRELEASED_KEYSPEC_API
- REDISMODULE_GET_API(AddCommandKeySpec);
- REDISMODULE_GET_API(SetCommandKeySpecBeginSearchIndex);
- REDISMODULE_GET_API(SetCommandKeySpecBeginSearchKeyword);
- REDISMODULE_GET_API(SetCommandKeySpecFindKeysRange);
- REDISMODULE_GET_API(SetCommandKeySpecFindKeysKeynum);
-#endif
REDISMODULE_GET_API(Yield);
REDISMODULE_GET_API(GetThreadSafeContext);
REDISMODULE_GET_API(GetDetachedThreadSafeContext);
@@ -1320,6 +1449,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(AuthenticateClientWithUser);
REDISMODULE_GET_API(GetClientCertificate);
REDISMODULE_GET_API(GetCommandKeys);
+ REDISMODULE_GET_API(GetCommandKeysWithFlags);
REDISMODULE_GET_API(GetCurrentCommandName);
REDISMODULE_GET_API(RegisterDefragFunc);
REDISMODULE_GET_API(DefragAlloc);
@@ -1347,7 +1477,6 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
/* Things only defined for the modules core, not exported to modules
* including this file. */
#define RedisModuleString robj
-#define RedisModuleCommandArg redisCommandArg
#endif /* REDISMODULE_CORE */
#endif /* REDISMODULE_H */