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
6bb8cdae
Commit
6bb8cdae
authored
Dec 20, 2018
by
antirez
Browse files
Modules shared API: unregister APIs function.
parent
27f6e9bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
6bb8cdae
...
...
@@ -4700,6 +4700,29 @@ void *RM_GetSharedAPI(RedisModuleCtx *ctx, const char *apiname) {
return
sapi
->
func
;
}
/* Remove all the APIs registered by the specified module. Usually you
* want this when the module is going to be unloaded. This function
* assumes that's caller responsibility to make sure the APIs are not
* used by other modules.
*
* The number of unregistered APIs is returned. */
int
moduleUnregisterSharedAPI
(
RedisModule
*
module
)
{
int
count
=
0
;
dictIterator
*
di
=
dictGetSafeIterator
(
server
.
sharedapi
);
dictEntry
*
de
;
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
const
char
*
apiname
=
dictGetKey
(
de
);
RedisModuleSharedAPI
*
sapi
=
dictGetVal
(
de
);
if
(
sapi
->
module
==
module
)
{
dictDelete
(
server
.
sharedapi
,
apiname
);
zfree
(
sapi
);
count
++
;
}
}
dictReleaseIterator
(
di
);
return
count
;
}
/* --------------------------------------------------------------------------
* Modules API internals
* -------------------------------------------------------------------------- */
...
...
@@ -4843,6 +4866,7 @@ int moduleLoad(const char *path, void **module_argv, int module_argc) {
if
(
onload
((
void
*
)
&
ctx
,
module_argv
,
module_argc
)
==
REDISMODULE_ERR
)
{
if
(
ctx
.
module
)
{
moduleUnregisterCommands
(
ctx
.
module
);
moduleUnregisterSharedAPI
(
ctx
.
module
);
moduleFreeModuleStructure
(
ctx
.
module
);
}
dlclose
(
handle
);
...
...
@@ -4880,6 +4904,7 @@ int moduleUnload(sds name) {
}
moduleUnregisterCommands
(
module
);
moduleUnregisterSharedAPI
(
module
);
/* Remove any notification subscribers this module might have */
moduleUnsubscribeNotifications
(
module
);
...
...
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