mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 16:48:27 -05:00
Modules shared API: unregister APIs function.
This commit is contained in:
parent
27f6e9bb9b
commit
6bb8cdaebe
25
src/module.c
25
src/module.c
@ -4700,6 +4700,29 @@ void *RM_GetSharedAPI(RedisModuleCtx *ctx, const char *apiname) {
|
|||||||
return sapi->func;
|
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
|
* 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 (onload((void*)&ctx,module_argv,module_argc) == REDISMODULE_ERR) {
|
||||||
if (ctx.module) {
|
if (ctx.module) {
|
||||||
moduleUnregisterCommands(ctx.module);
|
moduleUnregisterCommands(ctx.module);
|
||||||
|
moduleUnregisterSharedAPI(ctx.module);
|
||||||
moduleFreeModuleStructure(ctx.module);
|
moduleFreeModuleStructure(ctx.module);
|
||||||
}
|
}
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
@ -4880,6 +4904,7 @@ int moduleUnload(sds name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moduleUnregisterCommands(module);
|
moduleUnregisterCommands(module);
|
||||||
|
moduleUnregisterSharedAPI(module);
|
||||||
|
|
||||||
/* Remove any notification subscribers this module might have */
|
/* Remove any notification subscribers this module might have */
|
||||||
moduleUnsubscribeNotifications(module);
|
moduleUnsubscribeNotifications(module);
|
||||||
|
Loading…
Reference in New Issue
Block a user