redis中如何保持关系数据库里的一行记录
高洛峰
高洛峰 2017-04-24 09:10:58
0
4
624

要将关系数据库中表的一行记录保持到redis中,在redis里要采用哪种数据类型,怎么保存?希望能举个具体示例

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
伊谢尔伦

Serialize java objects and store them as byte arrays

洪涛

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).

刘奇

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

洪涛

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template