D
D
dzoid2017-07-12 23:20:38
PHP
dzoid, 2017-07-12 23:20:38

Drop data from REDIS to MYSQL after key expires?

It is necessary to use php + redis + mysql to read and store pageviews of each material on the site.
I would like to do this:
1. We get data from mysql and save the value to a redis key with a key lifetime of 5 minutes
2. We increase the value of the REDIS key
3. When the key lifetime ends, a callback is made to the function that does UPDATE `news` SET `pageviews` =$newvalue
$newvalue is what REDIS calculated.
There is one question - if after 4 minutes 59 seconds there are no calls to the key ($redis->get()) - will the callback be executed (no data can be lost)?
Can you tell me how to implement this?
PS You can of course use cron to collect data from REDIS and update mysql, but I would like to use standard tools!
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2017-07-12
@ThunderCat

https://redis.io/topics/notifications
UPD: I re-read your porridge here, apparently your idea is this: we store a rapid increase in views with radish, once in a while we throw it into the muscle so as not to screw up in case of an asshole.
If so, why do we need a time of death? Write in the key all the way, once in a while throw it into the muscle, in the absence of a key on request (for example, there was a failure and the radish died) - we climb into the muscle, take out how much it was, put it in the radish and torture it further in the same mode. IMHO save a lot of resources on creating / killing keys.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question