mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-22 16:18:28 -05:00
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;
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user