Z
Z
zlodiak2019-12-06 01:58:38
Redis
zlodiak, 2019-12-06 01:58:38

How to organize caching with redis?

Please help me understand if I understand the organization of CRUD for non-critical data using redis. CREATE
operation :

начало транзакции
  запись в postgres
  запись в redis
конец транзакции

READ operation :
читать из redis
если не прочиталось из redis, то:
  читать из postgres

UPDATE operation :
начало транзакции
  обновить в redis
  обновить в postgres
конец транзакции

DELETE operation :
начало транзакции
  удалить в redis
  удалить в postgres
конец транзакции

As I see it, this gives some advantage in the form of a cache, but does not give a special increase in performance.
Would it be considered good practice for non-critical data not to use a relational database at all, but to use only redis? All the same, there is a periodic saving to disk, which the programmer can control.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2019-12-06
@leahch

No, you're all wrong! First, you DO NOT have a transaction on both postgres and radish at the same time, and this is the key point. Secondly, always do all updates in postgres with the key removed from the radish. Reading - first we read from the radish, and if not there, we climb into postgres and write the key to the radish.
And yes, if the data is not critical, such as counters, baskets, etc., then they can be stored in a radish.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question