Suppose dal uses php as an example.
Originally using php to operate mysql alone, now we need to squeeze the server and consider adding a redis. However, we have doubts about the access strategy of the two data sources at the same time, and hope to help sort it out.
It is better to explain it with pseudocode, thank you.
Just use redis as a cache, there is no need to write it in DAL inside (I don’t know what DAL means, just use DAO, AR, ORM, listen to names are similar things? ), just extend it in the form of Cache, such as inheriting your cache class, if there is any requirement for permanent storage, inherit DAL class and implement it with redis, if it is used as queue, or intersection union, counter, etc., also implement the existing interface through redis database.
Finally, a common entry file is used to call different implementations by constructing methods.
Pseudo-code cannot be written, since PHP directly posts open source projectsYii2-redis, look at which ActiveRecord.php and Cache.php, probably the idea is like this.