Django使用Redis缓存时出现Socket连接拒绝(Error 10061)求助
I see you’ve set up django-redis for caching in your Django project, but you’re hitting a connection refused error when accessing your site. Let’s work through this step by step:
Your Current Cache Configuration
CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': [ 'redis://127.0.0.1:6379', ], 'TIMEOUT': None, } }
The Error Details
ConnectionError at /exchange/provider
Error 10061 connecting to 127.0.0.1:6379. No connection could be made because the target machine actively refused it.Request Method: GET
Request URL: http://127.0.0.1:8000/exchange/provider
Django Version: 2.0.2
Exception Type: ConnectionError
Exception Location: redis/connection.py in connect, line 489
Python Version: 3.6.4
Fixes to Resolve the Issue
This error means Django can’t reach your local Redis server. Here are the most common solutions:
Check if Redis is running
On Windows, open the Services app (Win + R → typeservices.msc) and look for the Redis service—ensure it’s marked as "Running". If not, start it manually, or launch Redis directly via command line withredis-server.
On Linux/macOS, runsystemctl status redis(for systemd systems) orbrew services listif you installed Redis via Homebrew. Start it withsystemctl start redisorbrew services start redisif it’s inactive.Verify Redis listens on the correct address/port
Open your Redis config file (usuallyredis.conf) and check thebinddirective—it should be set to127.0.0.1(for local access) or0.0.0.0if you need external connections. Confirm theportsetting is6379(the default). Restart Redis after any config changes.Check firewall/security software
Windows Firewall or third-party antivirus might block connections to port 6379. Temporarily disable your firewall to test if that fixes the issue. If it does, add an inbound rule to allow traffic on port 6379 for Redis.Test the Redis connection directly
Runredis-cli pingin your terminal. APONGresponse means Redis is working correctly, and the issue might lie elsewhere (though your Django config looks valid). If you get a connection error here, the problem is with Redis itself.
内容的提问来源于stack exchange,提问作者Sam Drescher




