Using Redis In Django
What Is Redis
Redis is a key-value, in-memory database with TTL features and more. Mostly Redis is used for caching Pub/Sub and etc… One Of its Amazing features is TTL(Time To Live). TTL means we can set how many seconds the data will be live in Redis.
How To Add Redis In Django Framework
Things To Do Before Work With Redis In DEV Mode
First Install Redis On Your Local Machine
For Windows Machines Use This Like
Connect With Django Framework
Install Redis Package in Your Django Project
At Default Redis Works On PORT 6379
You Can Also Use Redis Form URL (like Heroku, AWS, etc)
You Can Set Your URL in the settings file and import it.
All Set Now You Can Use Redis With Django.
Learn Some Basic Redis Commands
SET — Write Data to the DB
GET — Get the Data from The DB
SETX — Works As Same As SET but has an extra parameter to TTL
Implementation
In This Code, The name Riyazur Razak Is Present For 120 Seconds. After 120 Seconds the value Riyazur Razak For the key name will be deleted automatically. This Is very Useful for generating OTPs etc…
That's All. Very Easy Steps To Add Redis With Your Django Project.