PHP中文网2017-04-24 09:12:58
You can directly use the primary key of the database as redis, such as <YOUR_PREFIX><PRIMARY_KEY>
. For content, for example, you can directly record json in the data table
Then there’s the issue of consistency
The first solution is to use redis as a cache. When reading records according to the primary key, first check whether there is one in redis (get). If not, get it from the database and set the corresponding value in redis. , it is best to set an expire time for the record when setting, so that even if the dirty data is not actively cleared, the new value can be automatically obtained through the expire mechanism after a period of time. When the data table records change, just delete the records in redis directly. This is a safer approach that I recommend.
The second option is to handle all data reading and writing directly in redis, and only write the data back to the database at specific times. Regarding the writeback mechanism, you can consider using a message queue to write data back asynchronously every time redis is modified. You can use a timestamp to ensure that the data written back to the database is the latest; or you can consider using Redis’ notification mechanism for expire timing (but this mechanism is not guaranteed, see http://redis.io/topics/notifications).
怪我咯2017-04-24 09:12:58
This is quite troublesome
You can refer to this article
http://www.cnblogs.com/enjiex/p/3618546.html
It can support simple additions, deletions, modifications and queries, and can be combined with redis transactions to implement simple functions
But it is very troublesome to implement the basic SQL operations of rdbms
In summary
PHP中文网2017-04-24 09:12:58
Read the manual obediently. The answers others give you will not be useful. The manual explains it very clearly. After reading the manual, consider the application scenarios. When it comes to the practical stage, there are some encapsulated third-party APIs that can be called. In fact, you The same goes for writing it yourself. Start writing from sockets and you will have a new understanding of protocols, languages, and networks