Addition of OnUnload function

This commit is contained in:
Jim Brunner 2019-03-13 16:31:24 +00:00
parent e5acc5ef4f
commit 283d6cfd58

View File

@ -4799,6 +4799,23 @@ int moduleUnload(sds name) {
errno = EBUSY;
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);