#Using Redis Cache System in deployed Django App?

5 messages · Page 1 of 1 (latest)

vapid pulsar
#

I managed to deploy my Django App on Railway.
For Caching i use Redis.

In my Django Code i still have my local Redis settings. Now i saw that i can add the Redis Service with one click to my project. But how do i need to adjust my code so that Redis works on my deployed app?

At the moment my cache settings look like this:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "myapp",
}
}

Project ID: 86f38f52-2ee4-462c-bb83-67e22c0db4bf

terse windBOT
#

Project ID: 86f38f52-2ee4-462c-bb83-67e22c0db4bf

vapid pulsar
#

I managed to make it work. Here is the solution:
Add the Redis URL, provided by Railway to the Location Parameter in your Cache Settings:

Use Redis as Cache System.

CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ.get("REDIS_URL", "redis://localhost:6379/0"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
"KEY_PREFIX": "myapp",
}
}

Add the env Variable Redis URL to your Variables in Railway and you should be good to go

queen ore
#

you are using variable references correct?

vapid pulsar
#

@queen ore correct 👍