After playing around with module API I found these 2 functions are good to have in a future release:

RedisModule_Onunload()

This function can be called before dlclose() the libmodule.so. The reason I think it is required is: 1. This function can release any internal dynamic memory required by the module. 2. It can also abort the blocked clients. According to https://github.com/antirez/redis/pull/4994, currently it is unsafe to unload modules that use the blocking api. Another possibility with this regard would be to automatically aborting all the clients by the core itself.

RedisModule_Onreload()

It seems there is no module reload command and issuing module load libmodule.so twice will actually do nothing since the second call to RedisModule_Init() will return error. Moreover, unloading and loading a module is impossible if the module exports new data-types:

/* modules.c ...
 * * EBUSY: The module exports a new data type and can only be reloaded. */
int moduleUnload(sds name) {...

So if I need to fix a minor bug in my module, I have to restart the Redis server. Having a mechanism to actually reload the module, by redefining and fixing the previously defined commands without restarting the server would be convenient.

Comment From: yossigo

Hey @halaei, I'm closing this as RedisModule_OnUnload was added by #5926.

The argument for a reload mechanism is interesting but I don't think it's realistic given the coupling between Redis and a loaded module (just think of all potential callbacks, etc.). And if a module does clean up and unregisters everything, that's essentially like unload/load.