In my current project, I have PostgreSQL as my main database, and Redis as a subordinate, for example, when some user adds another as a friend, the relationship will be stored in PostgreSQL first, and then the friends list in Redis will be updated. When a user list is requested, it will be pulled from Redis instead of PostgreSQL.
Question: when I update my friends list in Redis, should I get a new copy from PostgreSQL and replace the old list in Redis with a new one, or do I need to save the old list and just SADD userid to the list? The latter, of course, is best suited for performance, but intuitively does the former do the best job of maintaining data integrity? And if something like Celery is used, is the second method worth the risk?
Jiaji source
share