December, 11 2019
I worked as a Laravel backend developer at Qwickpage for a year. Qwickpage has lots of products that are still in their development stage but its is primarily a social network for entrepreneurs.
While at Qwickpage we have two instances of the core application running on the server. One is for development while the other is served live (production).
We make use of Redis as our caching system for the two instances of the app and the end result was a conflict.
The two applications (dev & live) were using the same instance of Redis on the server, each one keeps overriding the cached data of the other and returning wrong cached data.
We fixed this by creating another instance of Redis that runs on port 6380. So the live app takes port 6379 while dev app takes 6380; We now have two instances of Redis running on our server.
In this post, I will show you how you can create another instance of Redis on your Linux server. I will assume your already have Redis installed on your Linux server.
To create another instance of Redis we need to duplicate the existing Redis configuration file:
cp /etc/redis/redis_6379.conf /etc/redis/redis_6380.conf
Update port 6380 config file (etc/redis/redis_6380.conf) like this:
pidfile /var/run/redis_6380.pid
port 6380
logfile /var/log/redis/redis_6380.log
dir /var/lib/redis/6380
Create a port 6380 working directory:
mkdir /var/lib/redis/6380
Update port 6379 (/etc/init.d/redis_6379) service script from this:
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/etc/redis/6379.conf"
REDISPORT="6379"
to this:
NAME=`basename ${0}`
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/${NAME}.pid
CONF="/etc/redis/${NAME}.conf"
REDISPORT="${NAME#*_}"
Create a symlink script for port 6380 instance
ln -s /etc/init.d/redis_6379 /etc/init.d/redis_6380
To start the two Redis server instances run this:
/etc/init.d/redis_6379 start
/etc/init.d/redis_6380 start
You can now update the dotenv files of your two applications and assign them different Redis port respectively.
You can also follow me on twitter @stephenjude_
Be the first to hear about anything I publish, launch, or think is helpful for you. Subscribe here
Litehost is a web hosting platform for PHP & Laravel developers with Composer, Git, PHP & CLI pre-installed. Try it now