37

How to start redis-server on a different port than the default port 6379 in Ubuntu? I have used the following steps to install the redis:

sudo add-apt-repository ppa:rwky/redis
sudo apt-get update
sudo apt-get -y install redis-server

I installed it, but I don't know how to start redis-server on a different port than the default port 6379. So kindly tell me the steps to change the default port to different port?

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
klee
  • 1,554
  • 2
  • 19
  • 31

5 Answers5

65

redis-server --port 6380 will start a Redis server listening to port 6380.

redis-cli -p 6380 -- a suggestion made here as well -- does not start a Redis server listening to port 6380, but tries to connect the CLI to a (hopefully running) Redis server that listens to that port.

Jochem Schulenklopper
  • 6,452
  • 4
  • 44
  • 62
  • Huh, @ChristianMatthew? The question was "How to start redis-server on a different port" so the answer "redis-server --port 6380 will start a Redis server listening to port 6380" is clear, concise and correct. The question wasn't "Why ..." asking for an explanation, but just _how to_ do something. – Jochem Schulenklopper Dec 18 '19 at 20:08
  • The proper way to handle the question is to edit the question that it can fit your symantic reasoning and provide a full answer. In the OP's post he explains that he needs to know "how to do it." > I installed, but I don't know how to how to start redis-server on a different port than the default port 6379 > So kindly tell me the steps to change the default port to different port ? Where it says please tell me the steps this would be the "why" Even though he is saying why. Also, for other people coming across the question it would be more beneficial to properly answer the ques – Christian Matthew Dec 18 '19 at 22:23
  • Instead of remarking that my answer isn't the best explanation -- although it clearly answers the current question, without reading too much into the situation of the OP -- why don't you provide a better answer? – Jochem Schulenklopper Dec 19 '19 at 07:13
  • 1
    "Where it says please tell me the steps this would be the _why_" is obviously false. The OP is clearly asking for _how_, as stated in the title and the question text. – Jochem Schulenklopper Dec 19 '19 at 07:13
  • I was only offering a suggestion to you to make the answer better and more complete. – Christian Matthew Dec 19 '19 at 14:42
7
  1. Locate your redis.conf file (it will probably be at /etc/redis/6379.conf).
  2. Copy the file or edit that one and change the port directive to any free port.
  3. Start Redis with the new config file (note that if you've copied the file in the previous step, you'll need to change the service's startup script to use that file).
Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • I have one more question @Itamar, will that be a problem if I run 3 redis server in the same port on different machines(as master-slave)?? – AATHITH RAJENDRAN May 23 '19 at 03:58
6

in ubuntu 18.04

  sudo nano /etc/redis/redis.conf

and change the port

enter image description here

Yilmaz
  • 35,338
  • 10
  • 157
  • 202
6

To create a development server on your local machine you can simply use

redis-server --port 6380

Another options:

#redis-server --help

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 --replicaof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose
Mehmet Gökalp
  • 314
  • 3
  • 6
0

-p <port> Server port (default: 6379).

So if your instance is running under port 1985 just run

$redis-cli -p 1985
Rhumborl
  • 16,349
  • 4
  • 39
  • 45
  • 2
    Unfortunately, this does not answer the question. `redis-cli -p ` tries to connect the CLI to a Redis server listening to that port. The question was how to start a Redis _server_ listening on a different port. – Jochem Schulenklopper Apr 12 '18 at 08:38
  • 1
    With this cmd we can connect the CLI to already running Redis server in port 1985, but will not start redis server to listen in 1985. – AATHITH RAJENDRAN May 23 '19 at 03:53