How to start redis-server on a different port than the default port 6379 in ubuntu
Asked Answered
S

5

40

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?

Shelba answered 12/1, 2015 at 4:7 Comment(0)
H
75

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.

Heriot answered 12/4, 2018 at 8:37 Comment(5)
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.Heriot
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 quesIodize
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?Heriot
"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.Heriot
I was only offering a suggestion to you to make the answer better and more complete.Iodize
O
10

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
Overplus answered 29/12, 2020 at 14:29 Comment(0)
U
8
  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).
Unbecoming answered 12/1, 2015 at 8:29 Comment(1)
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)??Basement
E
7

in ubuntu 18.04

  sudo nano /etc/redis/redis.conf

and change the port

enter image description here

Ec answered 18/5, 2020 at 2:51 Comment(0)
S
0

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

So if your instance is running under port 1985 just run

$redis-cli -p 1985
Sturm answered 13/1, 2017 at 12:18 Comment(2)
Unfortunately, this does not answer the question. redis-cli -p <port> 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.Heriot
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.Basement

© 2022 - 2024 — McMap. All rights reserved.