How can I use redis with Django?


I've heard of redis-cache but how exactly does it work? Is it used as a layer between django and my rdbms, by caching the rdbms queries somehow?

Or is it supposed to be used directly as the database? Which I doubt, since that github page doesn't cover any login details, no setup.. just tells you to set some config property.

5/19/2016 6:01:40 PM

Accepted Answer

This Python module for Redis has a clear usage example in the readme:

Redis is designed to be a RAM cache. It supports basic GET and SET of keys plus the storing of collections such as dictionaries. You can cache RDBMS queries by storing their output in Redis. The goal would be to speed up your Django site. Don't start using Redis or any other cache until you need the speed - don't prematurely optimize.

7/15/2011 8:30:58 PM

Just because Redis stores things in-memory does not mean that it is meant to be a cache. I have seen people using it as a persistent store for data.

That it can be used as a cache is a hint that it is useful as a high-performance storage. If your Redis system goes down though you might loose data that was not been written back onto the disk again. There are some ways to mitigate such dangers, e.g. a hot-standby replica. If your data is 'mission-critical', like if you run a bank or a shop, Redis might not be the best pick for you. But if you write a high-traffic game with persistent live data or some social-interaction stuff and manage the probability of data-loss to be quite acceptable, then Redis might be worth a look.

Anyway, the point remains, yes, Redis can be used as a database.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow