Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting dynamic path in the redis.conf using the Environment variable

I have a environment variable MY_HOME which has a path to a directory /home/abc

Now, I have a redis.conf file In which I need to set this path like this

**redis.conf**

pidfile $MY_HOME/local/var/pids/redis.pid
logfile $MY_HOME/local/var/log/redis.log
dir $MY_HOME/local/var/lib/redis/

like we do in command line, so that my config file picks the path based on the Environment variable.

like image 265
Abibullah Rahamathulah Avatar asked Oct 18 '13 14:10

Abibullah Rahamathulah


People also ask

How do I access Redis config file?

The Redis configuration file is located at installdir/redis/etc/redis. conf.

What is config set?

Configsets are a set of configuration files used in a Solr installation: solrconfig. xml , the schema, and then resources like language files, synonyms. txt , DIH-related configuration, and others that are referenced from the config or schema.

Where is Redis config file in Windows?

folder: C:\Program Files\Redis\conf - there is some template conf file.


1 Answers

Because Redis can read its config from stdin, I do something very similar to what @jolestar suggested. I put placeholder variables in my redis.conf and then replace them using sed in my Redis launcher. For example:

==========
$MY_HOME/redis/redis.conf
==========
...
pidfile {DIR}/pids/server{n}.pid
port 123{n}
...

Then I have a script to start Redis:

==========
runredis.sh
==========
DIR=$MY_HOME/redis
for n in {1..4}; do
    echo "starting redis-server #$n ..."
    sed -e "s/{n}/$n/g" -e "s/{DIR}/$DIR/g" < $DIR/redis.conf | redis-server -
done

I've been using this approach forever and it works out well.

like image 179
dg99 Avatar answered Nov 15 '22 05:11

dg99