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
469a6e5f
Unverified
Commit
469a6e5f
authored
Oct 28, 2019
by
Salvatore Sanfilippo
Committed by
GitHub
Oct 28, 2019
Browse files
Merge pull request #6481 from guybe7/modules_notify
Modules: Allow notifying custom keyspace events
parents
cfcb4754
cee6dead
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
469a6e5f
...
@@ -3859,6 +3859,11 @@ const RedisModuleString *RM_GetKeyNameFromIO(RedisModuleIO *io) {
...
@@ -3859,6 +3859,11 @@ const RedisModuleString *RM_GetKeyNameFromIO(RedisModuleIO *io) {
return
io
->
key
;
return
io
->
key
;
}
}
/* Returns a RedisModuleString with the name of the key from RedisModuleKey */
const
RedisModuleString
*
RM_GetKeyNameFromModuleKey
(
RedisModuleKey
*
key
)
{
return
key
?
key
->
key
:
NULL
;
}
/* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Logging
* Logging
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
...
@@ -4368,6 +4373,20 @@ int RM_SubscribeToKeyspaceEvents(RedisModuleCtx *ctx, int types, RedisModuleNoti
...
@@ -4368,6 +4373,20 @@ int RM_SubscribeToKeyspaceEvents(RedisModuleCtx *ctx, int types, RedisModuleNoti
return
REDISMODULE_OK
;
return
REDISMODULE_OK
;
}
}
/* Get the configured bitmap of notify-keyspace-events (Could be used
* for additional filtering in RedisModuleNotificationFunc) */
int
RM_GetNotifyKeyspaceEvents
()
{
return
server
.
notify_keyspace_events
;
}
/* Expose notifyKeyspaceEvent to modules */
int
RM_NotifyKeyspaceEvent
(
RedisModuleCtx
*
ctx
,
int
type
,
const
char
*
event
,
RedisModuleString
*
key
)
{
if
(
!
ctx
||
!
ctx
->
client
)
return
REDISMODULE_ERR
;
notifyKeyspaceEvent
(
type
,
(
char
*
)
event
,
key
,
ctx
->
client
->
db
->
id
);
return
REDISMODULE_OK
;
}
/* Dispatcher for keyspace notifications to module subscriber functions.
/* Dispatcher for keyspace notifications to module subscriber functions.
* This gets called only if at least one module requested to be notified on
* This gets called only if at least one module requested to be notified on
* keyspace notifications */
* keyspace notifications */
...
@@ -6471,6 +6490,7 @@ void moduleRegisterCoreAPI(void) {
...
@@ -6471,6 +6490,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
StringCompare
);
REGISTER_API
(
StringCompare
);
REGISTER_API
(
GetContextFromIO
);
REGISTER_API
(
GetContextFromIO
);
REGISTER_API
(
GetKeyNameFromIO
);
REGISTER_API
(
GetKeyNameFromIO
);
REGISTER_API
(
GetKeyNameFromModuleKey
);
REGISTER_API
(
BlockClient
);
REGISTER_API
(
BlockClient
);
REGISTER_API
(
UnblockClient
);
REGISTER_API
(
UnblockClient
);
REGISTER_API
(
IsBlockedReplyRequest
);
REGISTER_API
(
IsBlockedReplyRequest
);
...
@@ -6485,6 +6505,8 @@ void moduleRegisterCoreAPI(void) {
...
@@ -6485,6 +6505,8 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
DigestAddStringBuffer
);
REGISTER_API
(
DigestAddStringBuffer
);
REGISTER_API
(
DigestAddLongLong
);
REGISTER_API
(
DigestAddLongLong
);
REGISTER_API
(
DigestEndSequence
);
REGISTER_API
(
DigestEndSequence
);
REGISTER_API
(
NotifyKeyspaceEvent
);
REGISTER_API
(
GetNotifyKeyspaceEvents
);
REGISTER_API
(
SubscribeToKeyspaceEvents
);
REGISTER_API
(
SubscribeToKeyspaceEvents
);
REGISTER_API
(
RegisterClusterMessageReceiver
);
REGISTER_API
(
RegisterClusterMessageReceiver
);
REGISTER_API
(
SendClusterMessage
);
REGISTER_API
(
SendClusterMessage
);
...
...
src/redismodule.h
View file @
469a6e5f
...
@@ -106,6 +106,11 @@
...
@@ -106,6 +106,11 @@
/* There is currently some background process active. */
/* There is currently some background process active. */
#define REDISMODULE_CTX_FLAGS_ACTIVE_CHILD (1<<18)
#define REDISMODULE_CTX_FLAGS_ACTIVE_CHILD (1<<18)
/* 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_KEYSPACE (1<<0)
/* K */
#define REDISMODULE_NOTIFY_KEYEVENT (1<<1)
/* E */
#define REDISMODULE_NOTIFY_GENERIC (1<<2)
/* g */
#define REDISMODULE_NOTIFY_GENERIC (1<<2)
/* g */
#define REDISMODULE_NOTIFY_STRING (1<<3)
/* $ */
#define REDISMODULE_NOTIFY_STRING (1<<3)
/* $ */
#define REDISMODULE_NOTIFY_LIST (1<<4)
/* l */
#define REDISMODULE_NOTIFY_LIST (1<<4)
/* l */
...
@@ -651,6 +656,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -651,6 +656,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
StringCompare
);
REDISMODULE_GET_API
(
StringCompare
);
REDISMODULE_GET_API
(
GetContextFromIO
);
REDISMODULE_GET_API
(
GetContextFromIO
);
REDISMODULE_GET_API
(
GetKeyNameFromIO
);
REDISMODULE_GET_API
(
GetKeyNameFromIO
);
REDISMODULE_GET_API
(
GetKeyNameFromModuleKey
);
REDISMODULE_GET_API
(
Milliseconds
);
REDISMODULE_GET_API
(
Milliseconds
);
REDISMODULE_GET_API
(
DigestAddStringBuffer
);
REDISMODULE_GET_API
(
DigestAddStringBuffer
);
REDISMODULE_GET_API
(
DigestAddLongLong
);
REDISMODULE_GET_API
(
DigestAddLongLong
);
...
@@ -703,6 +709,8 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
...
@@ -703,6 +709,8 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
AbortBlock
);
REDISMODULE_GET_API
(
AbortBlock
);
REDISMODULE_GET_API
(
SetDisconnectCallback
);
REDISMODULE_GET_API
(
SetDisconnectCallback
);
REDISMODULE_GET_API
(
SubscribeToKeyspaceEvents
);
REDISMODULE_GET_API
(
SubscribeToKeyspaceEvents
);
REDISMODULE_GET_API
(
NotifyKeyspaceEvent
);
REDISMODULE_GET_API
(
GetNotifyKeyspaceEvents
);
REDISMODULE_GET_API
(
BlockedClientDisconnected
);
REDISMODULE_GET_API
(
BlockedClientDisconnected
);
REDISMODULE_GET_API
(
RegisterClusterMessageReceiver
);
REDISMODULE_GET_API
(
RegisterClusterMessageReceiver
);
REDISMODULE_GET_API
(
SendClusterMessage
);
REDISMODULE_GET_API
(
SendClusterMessage
);
...
...
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