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:
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:
Locate the entry as shown below and change the value to your desired port.
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:
You can learn more by checking the redis-cli documentation.
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!