Describe the bug
When building a redis module, environment variables are not exposed to the module.
To reproduce
Attached is sample code, and a Makefile. As long as you have gcc, running make will yield a redis module.
-
Untar the attached zip file (for reference, this includes a compiled version, on Arch latest). rediscrypt-bug.zip
-
cd into the directory and run make
-
Start the redis server, and load the module via redis.conf, by adding loadmodule dist/redicrypt.so from this folder into a redis.conf file.
-
Use the redis-cli to execute helloworld.rand by running redis-cli helloworld.rand
a. Restart your redis server by setting an environment variable in the command call, and repeat step 4. SOMETESTVAR=avalue redis-server redis.conf
b. Restart your redis server by setting an environment variable prior to the command call, and repeat step 4. export SOMETESTVAR=avalue && redis-server redis.conf
Expected behavior
I would expect the environment variables to be made available to the module, meaning I can get their values with getenv. Running redis-cli hellworld.rand should output the value of the environment variable.
Comment From: yossigo
@chayim I don't manage to reproduce this problem. Specifically with the example you provide, the problem is with the printf and not the getenv -- it would go to the server's stdout and vanish.
You can confirm this by returning the value instead:
int HelloworldRand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_ReplyWithSimpleString(ctx,getenv("SOMETESTVAR"));
return REDISMODULE_OK;
}
Comment From: chayim
This works perfectly - confirmed. It's possible that I had an environment issue. Closing.