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
2a5aeef7
Commit
2a5aeef7
authored
Mar 18, 2019
by
Yossi Gottlieb
Browse files
CommandFilter API: More cleanup.
parent
9095e4dc
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
2a5aeef7
...
@@ -270,32 +270,23 @@ typedef struct RedisModuleDictIter {
...
@@ -270,32 +270,23 @@ typedef struct RedisModuleDictIter {
raxIterator
ri
;
raxIterator
ri
;
}
RedisModuleDictIter
;
}
RedisModuleDictIter
;
/* Information about the command to be executed, as passed to and from a
typedef
struct
RedisModuleCommandFilterCtx
{
* filter. */
typedef
struct
RedisModuleFilteredCommand
{
RedisModuleString
**
argv
;
RedisModuleString
**
argv
;
int
argc
;
int
argc
;
}
RedisModule
FilteredCommand
;
}
RedisModule
CommandFilterCtx
;
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleC
tx
*
ctx
,
RedisModuleFilteredCommand
*
cmd
);
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleC
ommandFilterCtx
*
filter
);
typedef
struct
RedisModuleCommandFilter
{
typedef
struct
RedisModuleCommandFilter
{
/* The module that registered the filter */
/* The module that registered the filter */
RedisModule
*
module
;
RedisModule
*
module
;
/* Filter callback function */
/* Filter callback function */
RedisModuleCommandFilterFunc
callback
;
RedisModuleCommandFilterFunc
callback
;
/* Indicates a filter is active, avoid reentrancy */
int
active
;
}
RedisModuleCommandFilter
;
}
RedisModuleCommandFilter
;
/* Registered filters */
/* Registered filters */
static
list
*
moduleCommandFilters
;
static
list
*
moduleCommandFilters
;
typedef
struct
RedisModuleCommandFilterCtx
{
RedisModuleString
**
argv
;
int
argc
;
}
RedisModuleCommandFilterCtx
;
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Prototypes
* Prototypes
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
...
@@ -4802,16 +4793,13 @@ int moduleUnregisterUsedAPI(RedisModule *module) {
...
@@ -4802,16 +4793,13 @@ int moduleUnregisterUsedAPI(RedisModule *module) {
/* Register a new command filter function. Filters get executed by Redis
/* Register a new command filter function. Filters get executed by Redis
* before processing an inbound command and can be used to manipulate the
* before processing an inbound command and can be used to manipulate the
* behavior of standard Redis commands. Filters must not attempt to
* behavior of standard Redis commands.
* perform Redis commands or operate on the dataset, and must restrict
* themselves to manipulation of the arguments.
*/
*/
int
RM_RegisterCommandFilter
(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilterFunc
callback
)
{
int
RM_RegisterCommandFilter
(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilterFunc
callback
)
{
RedisModuleCommandFilter
*
filter
=
zmalloc
(
sizeof
(
*
filter
));
RedisModuleCommandFilter
*
filter
=
zmalloc
(
sizeof
(
*
filter
));
filter
->
module
=
ctx
->
module
;
filter
->
module
=
ctx
->
module
;
filter
->
callback
=
callback
;
filter
->
callback
=
callback
;
filter
->
active
=
0
;
listAddNodeTail
(
moduleCommandFilters
,
filter
);
listAddNodeTail
(
moduleCommandFilters
,
filter
);
return
REDISMODULE_OK
;
return
REDISMODULE_OK
;
...
@@ -4824,26 +4812,19 @@ void moduleCallCommandFilters(client *c) {
...
@@ -4824,26 +4812,19 @@ void moduleCallCommandFilters(client *c) {
listNode
*
ln
;
listNode
*
ln
;
listRewind
(
moduleCommandFilters
,
&
li
);
listRewind
(
moduleCommandFilters
,
&
li
);
RedisModule
FilteredCommand
cmd
=
{
RedisModule
CommandFilterCtx
filter
=
{
.
argv
=
c
->
argv
,
.
argv
=
c
->
argv
,
.
argc
=
c
->
argc
.
argc
=
c
->
argc
};
};
while
((
ln
=
listNext
(
&
li
)))
{
while
((
ln
=
listNext
(
&
li
)))
{
RedisModuleCommandFilter
*
filter
=
ln
->
value
;
RedisModuleCommandFilter
*
f
=
ln
->
value
;
if
(
filter
->
active
)
continue
;
RedisModuleCtx
ctx
=
REDISMODULE_CTX_INIT
;
f
->
callback
(
&
filter
);
ctx
.
module
=
filter
->
module
;
filter
->
active
=
1
;
filter
->
callback
(
&
ctx
,
&
cmd
);
filter
->
active
=
0
;
moduleFreeContext
(
&
ctx
);
}
}
c
->
argv
=
cmd
.
argv
;
c
->
argv
=
filter
.
argv
;
c
->
argc
=
cmd
.
argc
;
c
->
argc
=
filter
.
argc
;
}
}
/* Return the number of arguments a filtered command has. The number of
/* Return the number of arguments a filtered command has. The number of
...
...
src/redismodule.h
View file @
2a5aeef7
...
@@ -163,7 +163,7 @@ typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value
...
@@ -163,7 +163,7 @@ typedef void (*RedisModuleTypeDigestFunc)(RedisModuleDigest *digest, void *value
typedef
void
(
*
RedisModuleTypeFreeFunc
)(
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
(
*
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
(
*
RedisModuleTimerProc
)(
RedisModuleCtx
*
ctx
,
void
*
data
);
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleCtx
*
ctx
,
RedisModuleCommandFilterCtx
*
filter
);
typedef
void
(
*
RedisModuleCommandFilterFunc
)
(
RedisModuleCommandFilterCtx
*
filter
);
#define REDISMODULE_TYPE_METHOD_VERSION 1
#define REDISMODULE_TYPE_METHOD_VERSION 1
typedef
struct
RedisModuleTypeMethods
{
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