Redis

How do I change the default port for Redis

Redis is a free, open-source in-memory data store famous for its very low latency. It provides a set of commands for working with the Redis cluster and its data. In this tutorial, we will learn how to use these commands to change the startup settings for the Redis cluster.

Basic

Once you install Redis on your server, you can start the server using the redis-server command. The command will initialize the Redis cluster allowing you to connect to it and execute commands.

By default, the Redis server will run on port 6379. You can change the default run port, as discussed in this tutorial.

Method 1 – Command Line Arguments.

The first method you to change the default run port for the Redis server is to use the command-line option.

For example, to tell Redis to start on port 9001, use the –port flag as shown in the example command:

redis-server --port 9001

Method 2 – Configuration File

We started the Redis server on a custom port by specifying the –port argument in the discussed method.

This method will require you to specify the port every time you restart the server.

You can edit the Redis server configuration file and specify the startup port to make the changes permanent.

Open the terminal and edit the configuration as:

sudo nano /etc/redis/redis.conf

Locate the entry as shown below and change the value to your desired port.

port 6379

Once you set your desired port, save and close the file.

Next, restart the Redis service to apply the changes.

Connecting to custom port

After changing the default port on the Redis cluster, you will need to specify the port when connecting using the Redis CLI. You can use the command as shown below:

redis-cli -h localhost -p 9001

You can learn more by checking the redis-cli documentation.

Conclusion

This guide discussed various methods to change the default port for your Redis cluster. It is good to ensure you have the permissions to edit the configuration files and restart services before making any changes.
Thank you for reading & stay tuned for more Redis content!

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list