当前位置:网站首页>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.
边栏推荐
- R language plot visualization: use plot to visualize the training set and test set after data division, use different shape label representation, training set, test set, and display training and test
- 六月集训(第24天) —— 线段树
- STM32F1与STM32CubeIDE编程实例-WS2812B全彩LED驱动(基于SPI+DMA)
- Py之toad:toad的简介、安装、使用方法之详细攻略
- 左手代码,右手开源,开源路上的一份子
- postgresql之List
- 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?
- GO语言-goroutine协程的使用
- API data interface for announcement of Hong Kong listed companies
- leetcode:1504. Count the number of all 1 sub rectangles
猜你喜欢

Multimeter resistance measurement diagram and precautions

Virtual machines on the same distributed port group but different hosts cannot communicate with each other

简谈企业Power BI CI /CD 实施框架

Method after charging the idea plug-in material theme UI

Unit contour creation method

A brief introduction to the lexical analysis of PostgreSQL

Brief discussion on the implementation framework of enterprise power Bi CI /cd

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

Go language concurrency model mpg model

动作捕捉系统用于地下隧道移动机器人定位与建图
随机推荐
leetcode 139. Word Break 单词拆分(中等)
GO语言并发模型-MPG模型
The difference between V-IF and v-show
As a developer, what is the most influential book for you?
左手代码,右手开源,开源路上的一份子
Laravel 8 realizes auth login
Esp32 series -- comparison of esp32 series
同样是初级测试工程师,为啥他薪资高?会这几点面试必定出彩
Preliminary study on AQS
IList of PostgreSQL
[ansible problem processing] remote execution user environment variable loading problem
MySQL log management, backup and recovery
专精特新“小巨人”再启动,“企业上云”数字赋能
I have been in the industry for 4 years and have changed jobs twice. I have learned a lot about software testing
postgresql之List
PgSQL queries the largest or smallest data of a field in a group
Qunhui synchronizes with alicloud OSS
June training (day 24) - segment tree
Some basic database operations (providing the original database information)
How to evaluate domestic reporting tools and Bi software