当前位置:网站首页>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.
边栏推荐
- Bert-whitening 向量降维及使用
- IDEA连接mysql自定义生成实体类代码
- leetcode. 12 --- integer to Roman numeral
- 兴业证券靠谱吗?开证券账户安全吗?
- Brief discussion on the implementation framework of enterprise power Bi CI /cd
- [deep learning] storage form of nchw, nhwc and chwn format data
- R语言plotly可视化:可视化模型在整个数据空间的分类轮廓线(等高线)、meshgrid创建一个网格,其中每个点之间的距离由mesh_size变量表示、使用不同的形状标签表征、训练、测试及分类标签
- openinstall携手书链:助力渠道数据分析,共创书联网时代
- 实战 | 记一次曲折的钓鱼溯源反制
- 怎样评价国产报表工具和BI软件
猜你喜欢

Application of motion capture system in positioning and mapping of mobile robot in underground tunnel

Mots clés pour la cartographie es; Ajouter une requête par mot - clé à la requête term; Changer le type de mot - clé de cartographie

A common defect management tool - Zen, which teaches you from installation to using the handle

Linux Installation cenos7 MySQL - 8.0.26

ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)

leetcode. 12 --- integer to Roman numeral

`Thymeleaf ` template engine comprehensive analysis

测试 H5 和小程序的区别,你真的知道吗?

专精特新“小巨人”再启动,“企业上云”数字赋能

Common singleton mode & simple factory
随机推荐
API data interface for announcement of Hong Kong listed companies
Mots clés pour la cartographie es; Ajouter une requête par mot - clé à la requête term; Changer le type de mot - clé de cartographie
MySQL日志管理、备份与恢复
一文搞定 UDP 和 TCP 高频面试题!
ES mapping之keyword;term查詢添加keyword查詢;更改mapping keyword類型
The difference between V-IF and v-show
左手代码,右手开源,开源路上的一份子
Method of establishing unity thermodynamic diagram
测试 H5 和小程序的区别,你真的知道吗?
box-sizing
打败 二叉树!
update+catroot+c000021a+critical service failed+drivers+intelide+viaide+000000f
常见的单例模式&简单工厂
MySQL title
Chapter 8 operation bit and bit string (4)
[bitbear story collection] June MVP hero story | technology practice collision realm thinking
R语言实战应用精讲50篇(二十三)-贝叶斯理论重要概念: 可信度Credibility, 模型Models, 和参数Parameters
Laravel8 uses faker to call factory to fill data
港股上市公司公告 API 数据接口
[sdx62] wcn685x IPA registration failure analysis and solution