In your case, if you can accept regular import from redis to mysql, it basically means that your business does not need mysql, because redis is not just a cache, the data stuffed into it is persisted to the hard disk. You can just read it directly from redis next time.
As for cache, it is generally read cache (write cache is very verbose to implement and not very reliable), and the synchronization strategy with the database needs to be added to your own code logic.
Suppose your original code logic is as follows:
$data = get_from_db($condition);
Now you need to change get_from_db to this
function get_from_db($condition)
{
$data = get_from_cache($condition);
if (!$data)
{
$data = get_from_db_directly($condition);
set_to_cache($condition, $data);
}
return $data;
}
In your case, if you can accept regular import from redis to mysql, it basically means that your business does not need mysql, because redis is not just a cache, the data stuffed into it is persisted to the hard disk. You can just read it directly from redis next time.
As for cache, it is generally read cache (write cache is very verbose to implement and not very reliable), and the synchronization strategy with the database needs to be added to your own code logic.
Suppose your original code logic is as follows:
Now you need to change get_from_db to this