The cache technology says that Redis people will always associate with memcached, and people who know them should know the following.
- Redis supports Key-value data types compared to memcached, and colleagues support storage of data structures such as list, set, hash, and so on.
- Redis supports backup of data, that is, Master-slave mode of data backup.
- Redis supports the persistence of data.
- Redis supports database features in many ways, so to speak he is a database system, and memcached simply k/v the cache.
- They are not very significant in terms of performance, and the reading aspect, especially for bulk read performance, memcached dominant. Of course, Redis also has his advantages, such as persistence, support for more data structures.
- Therefore, Redis should be chosen if there is a need for durable aspects or requirements for data types and processing.
- If the simple Key/value store should choose Memcached.
The storage mechanism of memcached is slab allocation mechanism.
Simply talk about the mechanism of slab allcation
Her main terms: 1, Page------allocated to slab memory space, the default is 1MB. After assigning to slab, cut into chunk according to the size of slab
2. Chunk------memory space for Cache records
3, Slab Class-----A specific size chunk group
Scenarios used by memcached:
Usually in the e-commerce system on the left side of the site will be the classification of goods, the middle is a list of product search results, you can view commodity information and business basic information and relevant business reputation information.
The general practice is :
Multiple queries from the database for the entire station of the product classification--->> recursive form your desired classification tree--->> enter processing data------->> display to the page
Memcached's approach:
The first time: Determine if there is a memcached cache in the classification if there is no execution SQL query, then put into the memcached, and then display to the interface
The second time: determine if the memcached cache has the classification if there is a direct read memcached cache, and then display to the interface
If you encounter the updated data, find the corresponding key value in memcached to remove it and reinsert it into the memcached cache.
Talking about the difference between Redis and memcached