The Redis Module API reference states that RedisModuleString can be used in the implementation of the command (https://redis.io/topics/modules-api-ref, RedisModule_RetainString) by using RedisModule_RetainString function. However, it is not possible to use RedisModuleString without memory leaks for implementing own native type, since no RedisModuleCtx value is passed to RedisModuleTypeFreeFunc function. And Redis module context is required in order to deallocate RedisModuleString with RedisModule_FreeString function. I see no way to free allocated or retained RedisModuleStrings when native data type need to be destroyed.
Comment From: dvirsky
One workaround is to create a thread safe context from NULL, but in general you should avoid using redis strings in your data types, it's problematic and wasteful when loading from RDB, since the strings loaded from rdb are already allocated for your use.
Comment From: dmrub
It would be nice if you explain this in the documentation in more detail. I finally decided to use sds strings, but assumed that using Redis strings would reduce memory usage since they are reference counted and can be shared.
Comment From: dvirsky
If you're using sds, make sure to protect your module's symbols from colliding with redis' own sds strings. IIRC in gcc you do this with -Bsymbolic-functions and in the mac os linker by exposing only the module entry point, in effect making the rest of the symbols private - -exported_symbol _RedisModule_OnLoad
Comment From: dmrub
Thanks. Is this documented somewhere ? I don't see such options in the Makefile in https://github.com/RedisLabs/RedisModulesSDK. There are -Bsymbolic for Linux and -undefined dynamic_lookup for Mac OS X.
Comment From: yossigo
Closing this, Module API documentation and in particular something that's more tutorial-like and not just reference are very much desired of course.