You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Django使用Redis缓存时出现Socket连接拒绝(Error 10061)求助

Redis Connection Refused (Error 10061) in Django with django-redis

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 → type services.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 with redis-server.
    On Linux/macOS, run systemctl status redis (for systemd systems) or brew services list if you installed Redis via Homebrew. Start it with systemctl start redis or brew services start redis if it’s inactive.

  • Verify Redis listens on the correct address/port
    Open your Redis config file (usually redis.conf) and check the bind directive—it should be set to 127.0.0.1 (for local access) or 0.0.0.0 if you need external connections. Confirm the port setting is 6379 (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
    Run redis-cli ping in your terminal. A PONG response 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

火山引擎 最新活动