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
764b420f
Unverified
Commit
764b420f
authored
Oct 29, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Oct 29, 2019
Browse files
Merge pull request #6487 from oranagra/module_modified_key
Module API for explicit SignalModifiedKey instead of implicit one.
parents
568dfd4b
a12f0779
Changes
2
Show whitespace changes
Inline
Side-by-side
src/module.c
View file @
764b420f
...
@@ -322,6 +322,13 @@ static struct RedisModuleForkInfo {
...
@@ -322,6 +322,13 @@ static struct RedisModuleForkInfo {
#define REDISMODULE_ARGV_NO_AOF (1<<1)
#define REDISMODULE_ARGV_NO_AOF (1<<1)
#define REDISMODULE_ARGV_NO_REPLICAS (1<<2)
#define REDISMODULE_ARGV_NO_REPLICAS (1<<2)
/* Determine whether Redis should signalModifiedKey implicitly.
* In case 'ctx' has no 'module' member (and therefore no module->options),
* we assume default behavior, that is, Redis signals.
* (see RM_GetThreadSafeContext) */
#define SHOULD_SIGNAL_MODIFIED_KEYS(ctx) \
ctx->module? !(ctx->module->options & REDISMODULE_OPTION_NO_IMPLICIT_SIGNAL_MODIFIED) : 1
/* Server events hooks data structures and defines: this modules API
/* Server events hooks data structures and defines: this modules API
* allow modules to subscribe to certain events in Redis, such as
* allow modules to subscribe to certain events in Redis, such as
* the start and end of an RDB or AOF save, the change of role in replication,
* the start and end of an RDB or AOF save, the change of role in replication,
...
@@ -822,6 +829,7 @@ void RM_SetModuleAttribs(RedisModuleCtx *ctx, const char *name, int ver, int api
...
@@ -822,6 +829,7 @@ void RM_SetModuleAttribs(RedisModuleCtx *ctx, const char *name, int ver, int api
module
->
filters
=
listCreate
();
module
->
filters
=
listCreate
();
module
->
in_call
=
0
;
module
->
in_call
=
0
;
module
->
in_hook
=
0
;
module
->
in_hook
=
0
;
module
->
options
=
0
;
ctx
->
module
=
module
;
ctx
->
module
=
module
;
}
}
...
@@ -852,6 +860,12 @@ void RM_SetModuleOptions(RedisModuleCtx *ctx, int options) {
...
@@ -852,6 +860,12 @@ void RM_SetModuleOptions(RedisModuleCtx *ctx, int options) {
ctx
->
module
->
options
=
options
;
ctx
->
module
->
options
=
options
;
}
}
/* Signals that the key is modified from user's perspective (i.e. invalidate WATCH). */
int
RM_SignalModifiedKey
(
RedisModuleCtx
*
ctx
,
RedisModuleString
*
keyname
)
{
signalModifiedKey
(
ctx
->
client
->
db
,
keyname
);
return
REDISMODULE_OK
;
}
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Automatic memory management for modules
* Automatic memory management for modules
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
...
@@ -1843,7 +1857,9 @@ void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
...
@@ -1843,7 +1857,9 @@ void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
/* Close a key handle. */
/* Close a key handle. */
void
RM_CloseKey
(
RedisModuleKey
*
key
)
{
void
RM_CloseKey
(
RedisModuleKey
*
key
)
{
if
(
key
==
NULL
)
return
;
if
(
key
==
NULL
)
return
;
if
(
key
->
mode
&
REDISMODULE_WRITE
)
signalModifiedKey
(
key
->
db
,
key
->
key
);
int
signal
=
SHOULD_SIGNAL_MODIFIED_KEYS
(
key
->
ctx
);
if
((
key
->
mode
&
REDISMODULE_WRITE
)
&&
signal
)
signalModifiedKey
(
key
->
db
,
key
->
key
);
/* TODO: if (key->iter) RM_KeyIteratorStop(kp); */
/* TODO: if (key->iter) RM_KeyIteratorStop(kp); */
RM_ZsetRangeStop
(
key
);
RM_ZsetRangeStop
(
key
);
decrRefCount
(
key
->
key
);
decrRefCount
(
key
->
key
);
...
@@ -6471,6 +6487,7 @@ void moduleRegisterCoreAPI(void) {
...
@@ -6471,6 +6487,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
ModuleTypeGetValue
);
REGISTER_API
(
ModuleTypeGetValue
);
REGISTER_API
(
IsIOError
);
REGISTER_API
(
IsIOError
);
REGISTER_API
(
SetModuleOptions
);
REGISTER_API
(
SetModuleOptions
);
REGISTER_API
(
SignalModifiedKey
);
REGISTER_API
(
SaveUnsigned
);
REGISTER_API
(
SaveUnsigned
);
REGISTER_API
(
LoadUnsigned
);
REGISTER_API
(
LoadUnsigned
);
REGISTER_API
(
SaveSigned
);
REGISTER_API
(
SaveSigned
);
...
...
src/redismodule.h
View file @
764b420f
...
@@ -166,6 +166,10 @@ typedef uint64_t RedisModuleTimerID;
...
@@ -166,6 +166,10 @@ typedef uint64_t RedisModuleTimerID;
/* Declare that the module can handle errors with RedisModule_SetModuleOptions. */
/* Declare that the module can handle errors with RedisModule_SetModuleOptions. */
#define REDISMODULE_OPTIONS_HANDLE_IO_ERRORS (1<<0)
#define REDISMODULE_OPTIONS_HANDLE_IO_ERRORS (1<<0)
/* 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)
/* Server events definitions. */
/* Server events definitions. */
#define REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED 0
#define REDISMODULE_EVENT_REPLICATION_ROLE_CHANGED 0
...
@@ -439,6 +443,7 @@ RedisModuleType *REDISMODULE_API_FUNC(RedisModule_ModuleTypeGetType)(RedisModule
...
@@ -439,6 +443,7 @@ RedisModuleType *REDISMODULE_API_FUNC(RedisModule_ModuleTypeGetType)(RedisModule
void
*
REDISMODULE_API_FUNC
(
RedisModule_ModuleTypeGetValue
)(
RedisModuleKey
*
key
);
void
*
REDISMODULE_API_FUNC
(
RedisModule_ModuleTypeGetValue
)(
RedisModuleKey
*
key
);
int
REDISMODULE_API_FUNC
(
RedisModule_IsIOError
)(
RedisModuleIO
*
io
);
int
REDISMODULE_API_FUNC
(
RedisModule_IsIOError
)(
RedisModuleIO
*
io
);
void
REDISMODULE_API_FUNC
(
RedisModule_SetModuleOptions
)(
RedisModuleCtx
*
ctx
,
int
options
);
void
REDISMODULE_API_FUNC
(
RedisModule_SetModuleOptions
)(
RedisModuleCtx
*
ctx
,
int
options
);
int
REDISMODULE_API_FUNC
(
RedisModule_SignalModifiedKey
)(
RedisModuleCtx
*
ctx
,
RedisModuleString
*
keyname
);
void
REDISMODULE_API_FUNC
(
RedisModule_SaveUnsigned
)(
RedisModuleIO
*
io
,
uint64_t
value
);
void
REDISMODULE_API_FUNC
(
RedisModule_SaveUnsigned
)(
RedisModuleIO
*
io
,
uint64_t
value
);
uint64_t
REDISMODULE_API_FUNC
(
RedisModule_LoadUnsigned
)(
RedisModuleIO
*
io
);
uint64_t
REDISMODULE_API_FUNC
(
RedisModule_LoadUnsigned
)(
RedisModuleIO
*
io
);
void
REDISMODULE_API_FUNC
(
RedisModule_SaveSigned
)(
RedisModuleIO
*
io
,
int64_t
value
);
void
REDISMODULE_API_FUNC
(
RedisModule_SaveSigned
)(
RedisModuleIO
*
io
,
int64_t
value
);
...
@@ -637,6 +642,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -637,6 +642,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
ModuleTypeGetValue
);
REDISMODULE_GET_API
(
ModuleTypeGetValue
);
REDISMODULE_GET_API
(
IsIOError
);
REDISMODULE_GET_API
(
IsIOError
);
REDISMODULE_GET_API
(
SetModuleOptions
);
REDISMODULE_GET_API
(
SetModuleOptions
);
REDISMODULE_GET_API
(
SignalModifiedKey
);
REDISMODULE_GET_API
(
SaveUnsigned
);
REDISMODULE_GET_API
(
SaveUnsigned
);
REDISMODULE_GET_API
(
LoadUnsigned
);
REDISMODULE_GET_API
(
LoadUnsigned
);
REDISMODULE_GET_API
(
SaveSigned
);
REDISMODULE_GET_API
(
SaveSigned
);
...
...
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