Merge pull request #5926 from JimB123/unstable
Addition of RedisModule_OnUnload hook
This commit is contained in:
commit
b8e02f2b40
17
src/module.c
17
src/module.c
@ -5698,6 +5698,23 @@ int moduleUnload(sds name) {
|
|||||||
errno = EPERM;
|
errno = EPERM;
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Give module a chance to clean up. */
|
||||||
|
int (*onunload)(void *);
|
||||||
|
onunload = (int (*)(void *))(unsigned long) dlsym(module->handle, "RedisModule_OnUnload");
|
||||||
|
if (onunload) {
|
||||||
|
RedisModuleCtx ctx = REDISMODULE_CTX_INIT;
|
||||||
|
ctx.module = module;
|
||||||
|
ctx.client = moduleFreeContextReusedClient;
|
||||||
|
int unload_status = onunload((void*)&ctx);
|
||||||
|
moduleFreeContext(&ctx);
|
||||||
|
|
||||||
|
if (unload_status == REDISMODULE_ERR) {
|
||||||
|
serverLog(LL_WARNING, "Module %s OnUnload failed. Unload canceled.", name);
|
||||||
|
errno = ECANCELED;
|
||||||
|
return REDISMODULE_ERR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
moduleUnregisterCommands(module);
|
moduleUnregisterCommands(module);
|
||||||
moduleUnregisterSharedAPI(module);
|
moduleUnregisterSharedAPI(module);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user