6π
Turns out I needed to set up things like this for it to work on Heroku.
redis_url = os.getenv('REDISTOGO_URL')
urlparse.uses_netloc.append('redis')
url = urlparse.urlparse(redis_url)
conn = Redis(host=url.hostname, port=url.port, db=0, password=url.password)
124π
May be not directly related to your question but I was facing same error and it turn out that on my system redis-server package was not installed.
Problem was resolved with,
Ubuntu: sudo apt-get install redis-server
Cent OS: sudo yum install redis
- [Django]-Chaining multiple filter() in Django, is this a bug?
- [Django]-Django β getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-What's the difference between ContentType and MimeType?
28π
The solution is sudo apt-get install redis-server
.
Donβt forget to start your service by sudo service redis-server start
and you can use the command sudo service redis-server {start|stop|restart|force-reload|status}
for reference
- [Django]-How to access Enum types in Django templates
- [Django]-How exactly do Django content types work?
- [Django]-Django's self.client.login(β¦) does not work in unit tests
5π
I was facing same the error
-
Maybe radis server was not installed in your environment
sudo apt-get install redis-server
-
I needed to set up things like this in settings.py
redis_host = os.environ.get('REDIS_HOST', 'localhost') # Channel layer definitions # http://channels.readthedocs.org/en/latest/deploying.html#setting-up-a-channel-backend CHANNEL_LAYERS = { "default": { # This example app uses the Redis channel layer implementation asgi_redis "BACKEND": "asgi_redis.RedisChannelLayer", "CONFIG": { "hosts": [(redis_host, 6379)], }, "ROUTING": "multichat.routing.channel_routing", }, }
- [Django]-No module named urllib.parse (How should I install it?)
- [Django]-How Can I Disable Authentication in Django REST Framework
- [Django]-"Too many values to unpack" Exception
2π
if anyone comes here trying to get django_rq to work after encountering either 99 or 111 errors try the following:
RQ_QUEUES = {
"default": {
"HOST": "redis",
"PORT": "6379",
"URL": os.getenv("REDISTOGO_URL", "redis://redis:6379"), # If you're
"DB": 0,
"DEFAULT_TIMEOUT": 480,
}
}
this requires you to name the redis container like this in your docker-compose.yml
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python manage.py makemigrations &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000"
depends_on:
- redis
redis:
image: redis:6-alpine
ports:
- "6379:6379"
- [Django]-How to run a celery worker with Django app scalable by AWS Elastic Beanstalk?
- [Django]-Celery β Get task id for current task
- [Django]-Django template display item value or empty string
- [Django]-Django Framework β Is there a shutdown event that can be subscribed to?
- [Django]-Dynamic choices field in Django Models
- [Django]-Why is Django throwing error "DisallowedHost at /"?
1π
If you are using django_rq, a configuration like this will work for you:
RQ_QUEUES = {
'default': {
'HOST': 'localhost',
'PORT': '6379',
'URL': os.getenv('REDISTOGO_URL', 'redis://localhost:6379'), # If you're
'DB': 0,
'DEFAULT_TIMEOUT': 480,
}
}
It will make that work on your local environment and also on Heroku!
- [Django]-How to do SELECT MAX in Django?
- [Django]-ImportError: cannot import name 'β¦' from partially initialized module 'β¦' (most likely due to a circular import)
- [Django]-How to get primary keys of objects created using django bulk_create
1π
I also landed here with the following problem.
Trying again in 2.00 seconds...
[2019-06-10 07:25:48,432: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error 111 connecting to localhost:6379. Connection refused..
Trying again in 4.00 seconds...
[2019-06-10 07:25:52,439: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error 111 connecting to localhost:6379. Connection refused..
Trying again in 6.00 seconds...
[2019-06-10 07:25:58,447: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379//: Error 111 connecting to localhost:6379. Connection refused..
Trying again in 8.00 seconds...
I realized the problem was the ufw which was denying the connections.
Therefore, I allowed connections at this port using the following command.
sudo ufw allow 6379
This will set up a new rule in Ubuntuβs firewall that will allow connection from port 6397.
- [Django]-What is the clean way to unittest FileField in django?
- [Django]-Django: 'current_tags' is not a valid tag library
- [Django]-How can i test for an empty queryset in Django?
1π
I tried the following redis LOCATION URL and it worked
# caches
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://redis:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient"
},
"KEY_PREFIX": "example"
}
}
- [Django]-Django β No such table: main.auth_user__old
- [Django]-Find object in list that has attribute equal to some value (that meets any condition)
- [Django]-Django query filter with variable column
0π
Error 111 is thrown when the application is unable to contact Redis. I had the same problem following the Heroku Django Channels tutorial. The settings.py file should read:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [os.environ.get('REDISCLOUD_URL', 'redis://localhost:6379')],
},
"ROUTING": "chat.routing.channel_routing",
},
}
REDISCLOUD_URL
instead of REDIS_URL
.
Ensure Redis is installed on the Heroku server.
- [Django]-How do I convert a Django QuerySet into list of dicts?
- [Django]-Can we append to a {% block %} rather than overwrite?
- [Django]-What are the options for overriding Django's cascading delete behaviour?
0π
This could happen when whatever application that is calling/connecting to redis, the environment variable it consumed in order to specify a connection hasnβt been properly set β REDISCLOUD_URL
or REDISTOGO_URL
etc. This could most easily be that redis was started after the app or redis restarted and cycled its connection IP and/or access. So, upon deploying, insure redis is started prior to the downstream app(s)
Insure redis is up and running and a simple reboot on the app could fix the issue OR, as other answers have indicated, refresh the app in the appropriate manner to re-fresh & re-consume the environment variable.
- [Django]-Difference between filter with multiple arguments and chain filter in django
- [Django]-Generating file to download with Django
- [Django]-Object does not support item assignment error
0π
Right now Heroku automatically sets the environment variable REDIS_URL to URL + port.
A convenient way to work with redis on heroku is to use a connection pool:
settings.py
import redis
REDIS_DEFAULT_CONNECTION_POOL = redis.ConnectionPool.from_url(os.getenv('REDIS_URL', 'redis://localhost:6379/'))
whererver.py
from redis import Redis
from myProject.settings import REDIS_DEFAULT_CONNECTION_POOL
redis = Redis(connection_pool=REDIS_DEFAULT_CONNECTION_POOL)
print(redis.keys()) # works
- [Django]-FileUploadParser doesn't get the file name
- [Django]-Check if an object exists
- [Django]-How to export virtualenv?
0π
for me, I noticed that the port number was wrong, so I simply fixed it.
app = Celery("tasks", broker="redis://localhost:6379")
- [Django]-Delete multiple objects in django
- [Django]-Django include template from another app
- [Django]-How do I integrate Ajax with Django applications?