当前位置:网站首页>Analysis of similarities and differences between redis and memcached in cache use
Analysis of similarities and differences between redis and memcached in cache use
2022-06-24 14:35:00 【brookwang】
Understand their usage scenarios , We must first know their common ground and differences .
Common ground :
1.Memcached And Redis All belong to memory 、 Key value data storage scheme , All are nosql Outstanding representatives in the database .
2. Almost all major programming languages have support memcached and redis Client library , The easier , Very low threshold .
3. Both are data stored in memory , This also leads to almost the same characteristics ( And indicators ) performance 、 Data throughput and latency of the load .
4.Memcached And Redis The server can be easily installed in a few minutes , For learners, the cost is very low .
5.Memcached No authentication ,Redis There is no authentication by default .( Lack of authentication is also a reason to perform well under high loads , Of course, if someone knows the port and ip, The consequences are serious , This is also the current redis The biggest security risk , Many well-known Internet projects are not authenticated at present )
It's important , Differences :
1.Memcached Limit key names to 250 byte , The value is also limited to no more than 1MB, And it only applies to ordinary strings , Redis The key name and value of both support 512M,MC It is estimated that many people have encountered this pit .
2.Memcached Only string storage is supported , It almost limits its application scenario to just reading data ,Redis Support string , Hash , list , aggregate , Ordered set , Its application scenario expands instantly N times , Its rich internal functions and storage types support a variety of complex operations , There is a self increasing and self decreasing function in the list scene processing , The list can be queued in the queue processing scenario , Out of the team , Set functions can be added or deleted , Ordered sets can also be sorted , Calculation .
3.Memcached No data persistence scheme , Just restart , No data ,Redis It also provides optional and adjustable data persistence schemes ,RDB( snapshot ) and AOF( Copy ) Two kinds of , Administrators can control risks according to their needs , By setting... In the configuration file , keep redis Persist to disk for a certain period of time , Even restart when encountering , Power failure, etc , And keep the data still , This feature will be useful in some businesses redis As a persistent storage solution, it has a very positive significance .
4.Redis There is also a very important , Far better than Memcached Characteristics of ,Memcached No support for master-slave ,Redis It can provide replication function , Support the master and slave , The replication function can help the cache system to achieve a high availability configuration scheme , So as to continue to provide uninterrupted cache service for applications in case of failure , The master-slave configuration is also a standard configuration with high reliability .
5.Memcached Our data collection mechanism uses LRU( That is, the minimum recent use ) Algorithm ,Redis Adopt data recycling mechanism , It can delete old data from memory to provide the cache space necessary for new data .
6.Memcached No authentication ,Redis Although there is no authentication by default , But it supports authentication , Although almost no one has set up Authentication .
7.Memcached The maximum expiration time of is one month , Otherwise, it will fail to write ( I've stepped on this pit ),Redis There is no maximum expiration time limit yet , But because the caching mechanism is different , In less than 2.1.3 Of redis In the version , Only right key Set once expire.redis2.1.3 And later versions , You can do it many times key Use expire command , to update key Of expire time.
8.Redis A single thread ,Memcached Is a multithreaded , If the data structure is only KEY-VALUE, And VALUE Too much value for , It is best to Memcached, Because under single thread GET Oversized data , Can cause congestion , And so on Redis Slow sentences of ( Such as KEYS,HGETALL etc. ) It is better not to execute in the production environment .
9.Memcached The expiration policy of is lazy deletion ,Redis The expiration policy of is lazy deletion + Delete periodically .
(1) Expired deletion refers to the next GET If the value to is expired, it will be deleted .
(2) Periodic deletion refers to the random inspection of a specified quantity at regular intervals ( The default is 20) There is an expiration date KEY, If it expires, delete .
When Memcached When the used memory is greater than the set maximum memory usage , To make room for new data items ,Memcached It will start LRU Algorithm ( Recently at least use ) Obsolete data items .
So through the above analysis , although Redis And Memcached Both are excellent and proven caching solutions , Each have advantages and disadvantages .
10.Memcache Used Slab Allocator Memory allocation mechanism : According to the predetermined size , Splits allocated memory into blocks of a specific length , To completely solve the memory fragmentation problem .
Memcache The storage of involves slab,page,chunk Three concepts
1.Chunk For fixed size memory space , The default is 48Byte.
2.page Corresponding to the actual physical space ,1 individual page by 1M.
3. Same size chunk Also known as slab.
边栏推荐
- Online text entity extraction capability helps applications analyze massive text data
- 【环境搭建】zip 分卷压缩
- leetcode 139. Word break word split (medium)
- ES mapping之keyword;term查询添加keyword查询;更改mapping keyword类型
- Database considerations
- 在CVS中恢复到早期版本
- [ansible problem processing] remote execution user environment variable loading problem
- Restoring to an earlier version in CVS
- Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
- 成功解决:selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This versi
猜你喜欢

Stm32f1 and stm32cubeide programming examples -ws2812b full color LED driver (based on spi+dma)

不要小看了积分商城,它的作用可以很大

Data sharing between laravel lower views

Py之toad:toad的简介、安装、使用方法之详细攻略

MySQL log management, backup and recovery

Overview of SAP marketing cloud functions (III)

同样是初级测试工程师,为啥他薪资高?会这几点面试必定出彩

Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing

IDEA 插件 Material Theme UI收费后的办法

List of PostgreSQL
随机推荐
How to implement redis cache of highly paid programmers & interview questions series 115? How do I find a hot key? What are the possible problems with caching?
Win10 system problems
Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
怎样评价国产报表工具和BI软件
Cvpr2022 | domaine compact adaptable
Redis interview questions
Chapter 8 operation bit and bit string (4)
探索云原生数据库,纵观未来科技发展
中国十大证券app排名 炒股开户安全吗
动作捕捉系统用于地下隧道移动机器人定位与建图
09_ An efficient memory method
入行 4 年,跳槽 2 次,我摸透了软件测试这一行
Linux 安装 CenOS7 MySQL - 8.0.26
Online text entity extraction capability helps applications analyze massive text data
[pytoch] quantification
API data interface for announcement of Hong Kong listed companies
[ansible problem processing] remote execution user environment variable loading problem
手机注册股票开户 炒股开户安全吗
update+catroot+c000021a+critical service failed+drivers+intelide+viaide+000000f
一个简单而功能强大的开发者工具箱Box3.cc