Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to sync data from Mysql to Redis?

My website mostly use Django + Mysql and sometimes Redis for some frequently access data.

My problem is how to sync data from Mysql to Redis automatically when I write data to Mysql by Django admin page.

Thank you for giving me some advice. It also will be appreciated if someone can tell me how to write data into Redis directly by Django admin page

Thank you!

like image 605
JZAU Avatar asked Mar 02 '14 03:03

JZAU


1 Answers

What you want to achieve looks like using Redis as a cache. The pattern is:

Always look for the data in redis

If it's not in redis, get it from MySQL and store it in Redis with an expiration date, using the expire command

Doing it like this, you have to modify you app, not the admin page. But there could be a delay between the writing of the informations in the admin page, and their availability to the clients.

You may delete the data from the Redis cache in the admin, when storing them, to ensure the newest version will always be delivered. But you will have to modify Django admin page for this.

like image 174
Pascal Le Merrer Avatar answered Sep 30 '22 19:09

Pascal Le Merrer