9

I'm using kue which uses node_redis, but I'm also already using node_redis for my sessions, so I'd like to have kue create a server on a specific port say the default 6379 and then kue listen on port 1234.

How would I be able to do this? I found this article which talks about something similar, but I don't really want to have to create an init script to do this.

bob_cobb
  • 2,229
  • 11
  • 49
  • 109
  • Have you ever considered simply putting them in different databases? Redis default configuration has db 0 - 15. I have production servers running a workflow manager in 1 DB while another DB handles sessions. No need to run on 2 ports or run 2 instances. Being they are on the same machine it does not buy you anything to run 2 ports/instances. – Michael Papile Jul 10 '14 at 22:45

3 Answers3

23

Launch redis-server and supply a different argument for 'port' which can be done on the command-line:

edd@max:~$ redis-server -h
Usage: ./redis-server [/path/to/redis.conf] [options]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>

Examples:
       ./redis-server (run the server with default conf)
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --slaveof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel
edd@max:~$ 

You can do this from, say, /etc/rc.local as well so that this happens at startup.

But maybe you can also rethink your approach. Redis is so good at handling writes that you may just get by with a second database?

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks for the post, it helped me to realize that I don't even need a config file. Side note: I have a third party php script that uses flushall and wipes out all cache including my other application namespace. That's my reason to start another instance because flushall flushes all databases. – smozgur Dec 16 '17 at 17:39
  • Please do refer here -> https://bencane.com/2013/11/12/installing-redis-and-setting-up-master-slave-replication/ – Mani Kasi May 16 '22 at 07:29
2

Very easy command:

echo "port 4000" | redis-server -

echo "port 4001" | redis-server -

halfer
  • 19,824
  • 17
  • 99
  • 186
Amulya Kashyap
  • 2,333
  • 17
  • 25
-1

You can run multiple redis instance with different ports in a single machine.this concern is right mean you can follow the below steps.

By installing the first Redis instance, It listens on localhost:6379 by default.

  • For Second Instance
    create a new working directory

The default redis instance uses /var/lib/redis as its working directory, dumped memory content is saved under this directory with name dump.rdb if you did not change it manually.to avoid runtime conflict, we need to create a new working directory

mkdir -p /var/lib/redis2/
chown redis /var/lib/redis2/
chgrp redis /var/lib/redis2/

Generate configurations

Create a new configuration file by copying /etc/redis.conf

cp /etc/redis.conf /etc/redis2.conf
chown redis /etc/redis2.conf

Edit following settings to avoid conflicts

logfile "/var/log/redis/redis2.log"
dir "/var/lib/redis2"
pidfile "/var/run/redis/redis2.pid"
port 6380

Create service file

cp /usr/lib/systemd/system/redis.service /usr/lib/systemd/system/redis2.service

Modify the settings under Service section

[Service]
ExecStart=/usr/bin/redis-server /etc/redis2.conf --daemonize no
ExecStop=/usr/bin/redis-shutdown redis2

Set to start with boot

      systemctl enable redis2

Start 2nd redis

service redis2 start


check status

lsof -i:6379
lsof -i:6380

By Following this you can start two redis server.If you want more repeat the steps again.

Selva Kumar
  • 839
  • 1
  • 10
  • 15