Using the Redis cache backend
Django also provides a Redis cache backend. Let’s change the settings to use Redis instead of Memcached as the cache backend for the project. Remember that you already used Redis in Chapter 7, Tracking User Actions, and in Chapter 10, Extending Your Shop.
Install redis-py
in your environment using the following command:
python -m pip install redis==5.0.4
Then, edit the settings.py
file of the educa
project and modify the CACHES
setting, as follows:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://127.0.0.1:6379',
}
}
The project will now use the RedisCache
cache backend. The location is defined in the format redis://[host]:[port]
. You use 127.0.0.1
to point to the localhost and 6379
, which is the default port for Redis.
You can read more about the Redis cache backend at https://docs.djangoproject...