修改Redis端口为6380后仍连接默认6379端口问题求助
Hey there! Let's troubleshoot why Redis is still clinging to the default 6379 port even after you updated it to 6380. Below are step-by-step fixes sorted by likelihood:
1. Ensure Your Redis Config File is Applied Correctly
This is the most common culprit. Here's what to do:
- Locate your Redis config file (typically
redis.confon Linux,redis.windows.confon Windows). Open it and confirm the lineport 6380exists without a leading#(which would comment it out). - Restart the Redis service to apply the new config:
- On Linux with systemd:
sudo systemctl restart redis - On Linux using the direct command:
redis-server /path/to/your/redis.conf - On Windows: Stop the Redis service via Services or task manager, then restart it with the updated config file.
- On Linux with systemd:
- Verify Redis is listening on 6380:
- Linux: Run
netstat -tulpn | grep redis– you should see a line showing127.0.0.1:6380or0.0.0.0:6380. - Windows: Run
netstat -ano | findstr :6380– check if there's a process ID associated with this port.
- Linux: Run
2. Update Your Client Connection Settings
If Redis is running on 6380 but your client still tries 6379, you need to adjust the client's config:
- Redis CLI: Instead of just
redis-cli, useredis-cli -p 6380to explicitly specify the port. - Application Code: Check your app's Redis connection setup. For example:
- Python (redis-py):
import redis r = redis.Redis(host='127.0.0.1', port=6380, db=0) - Java (Jedis):
Jedis jedis = new Jedis("127.0.0.1", 6380);
- Python (redis-py):
- Environment Variables: If your app uses variables like
REDIS_PORT, make sure it's set to6380instead of6379.
3. Stop Any Stale Redis Instances
Sometimes the old 6379 instance keeps running in the background, causing confusion:
- Linux: List all Redis processes with
ps aux | grep redis-server, then kill the stale one withkill <process_id>. - Windows: Open Task Manager, find any
redis-server.exeprocesses, and end them. Then restart Redis with your 6380 config.
4. Double-Check for Socket/Pipe Configs (Less Common)
If your Redis config uses Unix sockets (Linux) or named pipes (Windows) instead of TCP, clients might default to that. Confirm:
- In
redis.conf, check ifunixsocketis enabled. If you want to use TCP port 6380, ensure this setting isn't overriding your port config, or update your client to use the socket path instead.
Start with the first two steps – they resolve 90% of this issue. If you still run into problems, feel free to share more details about your setup (OS, client type, etc.)!
内容的提问来源于stack exchange,提问作者Shaik




