Merge pull request #5926 from JimB123/unstable

Addition of RedisModule_OnUnload hook
This commit is contained in:
Salvatore Sanfilippo 2019-10-16 11:13:12 +02:00 committed by GitHub
commit b8e02f2b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5698,6 +5698,23 @@ int moduleUnload(sds name) {
errno = EPERM;
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);
moduleUnregisterSharedAPI(module);