Tuesday, July 2, 2013

Running multiple Redis instances on the same server

Redis runs as a background process that listens to a specific port (6379 by default) for incoming requests from clients. Running multiple instances requires a separate conf file and a new init script. The conf file specifies details for the new instance, and the init script handles starting/stopping of the instance background process.

  1. Make a copy of the redis.conf file at C:\Program Files\Redis\Conf and give it a new name redis-s1.conf. Leave both files in the same directory C:\Program Files\Redis\Conf
  2. Open the redis-s1.conf with your favorite text editor (e.g. notepad ) and change the following:
    1. PID File
      • pidfile /var/run/redis-s1.pid
    2. Port
      • port 6380
    3. Log File
      • logfile "C:/Program Files/Redis/logs/redis-s1.log
    4. Data Directory (don’t forget to create that directory)
      • dir "C:/Program Files/Redis/data2"
    5. For replication only : If you planning to use this instance as a slave in master-slave replication setting (where 127.0.0.1 is the master instance IP, 6379 in the master instance port)
      • slaveof 127.0.0.1 6379
  3. To start the new instance
    1. Open a new command window
    2. Navigate to C:\Program Files\Redis
    3. Run redis-server conf\redis-s1.conf
  4. To connect to the new instance
    1. Open a new command window
    2. Navigate to C:\Program Files\Redis
    3. Run redis-cli –h 127.0.0.1 –p 6380

Now you can have multiple Redis instances on the same server like any other DBMS.