Basics of redis
Redis stands for Remote Dictionary Server. Redis is a NO-SQL database that stores data in key-value format. In this blog, we will learn about the redis port. We will also understand how to check and change the redis default port. so let’s get started.
You can also check my below blogs to get familiar with redis.
Check redis port
There are many ways in which a user can check the port on which the redis is running. By default, the redis runs of port 6379.
1. Check Redis port while connecting to redis
When connecting to redis, usually redis will show you the host and port on which the redis is running.
root@f1322de9d190: redis-cli
127.0.0.1:6379>
From the above command, it is clear that the redis is running on port 6379
2. Check the redis port using CLI
A user can also check the port on which the redis is running using the CLI command.
Type the below command to connect to redis
root@f1322de9d190: redis-cli
127.0.0.1:6379>
Once connected a user can use the CONFIG command to get the port details
127.0.0.1:6379> CONFIG GET PORT
1) "PORT"
2) "6379"
3. Check the Redis port in the configuration file
All the redis configuration is saved inside a config file called redis.conf. In the network session of redis.conf file a user can find details about the port
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
Change redis port
So far we have understood how to check the port in redis. In this session, we will understand how to change the port.
There are many ways using which a user can change the redis port. Some of them are:
1. Change the Redis port using the configuration file
A user can change the port by changing the port in redis.conf file. Let’s say now we want redis to connect to port 6479. So do the following changes in the config file
port 6479
Now restart the redis service
systemctl restart redis
Now while connecting to redis a user needs to specify the custom port. Type the below command to connect to redis
redis-cli -h localhost -p 6479
127.0.0.1:6479>
2. Change the Redis port using CLI
A user can also change the port in redis by using the CLI command.
First, connect to redis cli using the below command
root@f1322de9d190: redis-cli
127.0.0.1:6379>
Now type the CONFIG SET command to change the redis port to 6479
127.0.0.1:6379> CONFIG SET port 6479
OK
Verify if the port gets changed
127.0.0.1:6379> CONFIG GET port 6479
1) "port"
2) "6479"
Now exit the redis cli and type the below command to connect to the redis port 6479
127.0.0.1:6379> exit
root@f1322de9d190: redis-cli -h localhost -p 6479
localhost:6479>
Conclusion
I hope you have liked this tutorial about redis port. Please do let me know if you are facing any issues while following along.