Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6dd5bad4
Commit
6dd5bad4
authored
Mar 18, 2019
by
Yossi Gottlieb
Committed by
antirez
May 13, 2019
Browse files
CommandFilter API: More cleanup.
parent
83026101
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
6dd5bad4
...
...
@@ -270,32 +270,23 @@ typedef struct RedisModuleDictIter {
raxIterator ri;
} RedisModuleDictIter;
/* Information about the command to be executed, as passed to and from a
* filter. */
typedef struct RedisModuleFilteredCommand {
typedef struct RedisModuleCommandFilterCtx {
RedisModuleString **argv;
int argc;
} RedisModule
FilteredCommand
;
} RedisModule
CommandFilterCtx
;
typedef void (*RedisModuleCommandFilterFunc) (RedisModuleC
tx *ctx, RedisModuleFilteredCommand *cmd
);
typedef void (*RedisModuleCommandFilterFunc) (RedisModuleC
ommandFilterCtx *filter
);
typedef struct RedisModuleCommandFilter {
/* The module that registered the filter */
RedisModule *module;
/* Filter callback function */
RedisModuleCommandFilterFunc callback;
/* Indicates a filter is active, avoid reentrancy */
int active;
} RedisModuleCommandFilter;
/* Registered filters */
static list *moduleCommandFilters;
typedef struct RedisModuleCommandFilterCtx {
RedisModuleString **argv;
int argc;
} RedisModuleCommandFilterCtx;
/* --------------------------------------------------------------------------
* Prototypes
* -------------------------------------------------------------------------- */
...
...
@@ -4804,16 +4795,13 @@ int moduleUnregisterUsedAPI(RedisModule *module) {
/* Register a new command filter function. Filters get executed by Redis
* before processing an inbound command and can be used to manipulate the
* behavior of standard Redis commands. Filters must not attempt to
* perform Redis commands or operate on the dataset, and must restrict
* themselves to manipulation of the arguments.
* behavior of standard Redis commands.
*/
int RM_RegisterCommandFilter(RedisModuleCtx *ctx, RedisModuleCommandFilterFunc callback) {
RedisModuleCommandFilter *filter = zmalloc(sizeof(*filter));
filter->module = ctx->module;
filter->callback = callback;
filter->active = 0;
listAddNodeTail(moduleCommandFilters, filter);
return REDISMODULE_OK;
...
...
@@ -4826,26 +4814,19 @@ void moduleCallCommandFilters(client *c) {
listNode *ln;
listRewind(moduleCommandFilters,&li);
RedisModule
FilteredCommand cmd
= {
RedisModule
CommandFilterCtx filter
= {
.argv = c->argv,
.argc = c->argc
};
while((ln = listNext(&li))) {
RedisModuleCommandFilter *filter = ln->value;
if (filter->active) continue;
RedisModuleCommandFilter *f = ln->value;
RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
ctx.module = filter->module;
filter->active = 1;
filter->callback(&ctx, &cmd);
filter->active = 0;
moduleFreeContext(&ctx);
f->callback(&filter);
}
c->argv =
cmd
.argv;
c->argc =
cmd
.argc;
c->argv =
filter
.argv;
c->argc =
filter
.argc;
}
/* Return the number of arguments a filtered command has. The number of
...
...
src/redismodule.h
View file @
6dd5bad4
...
...
@@ -163,7 +163,7 @@ typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value
typedef
void
(
*
RedisModuleTypeFreeFunc
)(
void
*
value
);
typedef
void
(
*
RedisModuleClusterMessageReceiver
)(
RedisModuleCtx
*
ctx
,
const
char
*
sender_id
,
uint8_t
type
,
const
unsigned
char
*
payload
,
uint32_t
len
);
typedef
void
(
*
RedisModuleTimerProc
)(
RedisModuleCtx
*
ctx
,
void
*
data
);
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilterCtx
*
filter
);
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleCommandFilterCtx
*
filter
);
#define REDISMODULE_TYPE_METHOD_VERSION 1
typedef
struct
RedisModuleTypeMethods
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment