脚本宝典收集整理的这篇文章主要介绍了Redis vs. Memcached – 2021 Comparison,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
来自:https://scalegrid.io/blog/redis-vs-memcached-2021-comparison/
参考:
https://stackoverflow.COM/questions/23601622/if-redis-is-already-a-part-of-the-stack-why-is-memcached-still-used-alongside-r/23650189#23650189
https://www.geeksforgeeks.org/difference-between-redis-and-memcached/
Redis stands for REmote DIctionary Server, created in 2009 by Salvatore Sanfilippo. memcached, on the other hand, was created in 2003 by brad FITzpatrick. Both Redis and Memcached are:
In 2014, Salvatore wrote an excellent StackOverflow post on when it makes more sense to use Memcached than Redis. In this post, we PRovide a current and detailed comparison between Redis and Memcached so that you can make an informed choice about their use in your application.
This post has been condensed down into the below infographic. With this infographic you can easily Visualize the results of this comparison to see which one comes out on top in different scenarios. If you want to read the comparison in text format, click here.Download the infographic
To start off, Redis is much more comprehensively documented than Memcached. This makes it easier to learn, administer and use.
Redis is primarily a key value Store. While keys are binary strings, the advantage with Redis is that the value is not limited to only binary strings. They can be a VARiety of data structures which enable storing of complex objects and provide a rich set of operations over them. Redis also provides for extensibility via Redis modules. Redis modules are extensions that provide for additional data structures and features not available within the core feature set. Here’s an sample of few features that are now available as modules:
Memcached is a plain key value store which only supports binary strings as value.
As mentioned above, Redis offers multiple data structure types allowing it to be extremely flexible to use, including Strings, Hashes, Lists, Sets, Sorted Sets, Bitmaps, Bitfields, HyperLOGLog, Geospatial indexes, and Streams. You can learn more about these in this Top Redis Use Cases by Core Data Structure Types article.
Image source: https://redislabs.com/redis-Enterprise/data-structures/
Memcached only supports plain binary strings which are great for read-only data, so if you don’t need all the bells and whistles of Redis, Memcached is a simpler database for you to use.
The greater popularity of a database results in a larger commUnity of users, more discussions and user-generated tutorials, and more help and support through third-party tools such as DBaaS platforms and analysis tools to help optimize your deployments.
Redis is the 8th most popular database in the world as of February 2021, according to DB-Engines because of its simplicity, rich data structures, and great documentation. Memcached is currently ranked as the 28th most popular database. When Redis and Memcached are ranked with respect to key-value database models, Redis stands in 1st and Memcached comes 4th. However, if you are looking only for an open-source key-value database, or one that can be deployed on-premise, Memcached comes in 2nd as both Amazon DynamoDB and Microsoft Azure Cosmos DB are both commercial databases that can only be deployed in the cloud.
Redis and Memcached both follow client-server architecture. Clients populate the data in the server in the form of key-value.
Redis is single threaded where on the other hand Memcached has a multithreaded architecture. Memcached scales better on a System with more cores that can handle more operations if compute capacity is scaled. However, more than one Redis instance can be initiated on the same system to utilize additional cores.
As explained above in the Database model section, Redis, being a multi-model database, can be used with any type of data model. In Redis, it is easy to write code as it simplifies complex tasks. Redis has advanced data structures and is not limited to simple string values. For instance, if your application stores data in sets and you want to keep track of sets in a list you can do this easily in Redis. A similar task on Memcached is not possible. But there are other ways to do the same tasks that will require more lines of code.
Memcached, on the other hand, only stores plain string values. So, the application is left to deal with the data structure complexity.
Redis supports partitioning of data across multiple node instances. Current users of Redis leverage different techniques like range partitioning, hash partitioning, and consistent hashing for data partitioning. In Redis, data partitioning can be implemented in three different ways:
Memcached also supports data partitioning across multiple nodes, and consistent hashing is a recommended approach to ensure the traffic load is evenly distributed.
Redis vs Memcached - 2021 ComparisonCLICK TO TWEET
Redis supports almost all of the most used programming languages, @R_777_2150@ high-level to low-level languages. Memcached however supports less number of languages compared to Redis, but does support all the popular languages.
Redis “transactions” are executed with the three below guarantees:
Redis makes sure that all only one command from one client machine is executed at once. All the commands in the transactions are executed when the “EXEC” command is called to ensure the atomicity.
Memcached, on the other hand, does not provide transaction management.
Redis offers a simple leader-follower (master-slave) replication that creates exact copies of the master instances, with these features:
You can also leverage the high availability features, Redis Sentinels or Redis Cluster, for advanced failover protection.
Native Memcached does not support replication, but you can use Repcached, a free open source patch to achieve high availability for your deployment. It offers multi master replication, asynchronous data replication, and supports all Memcached commands.
Snapshots are simply a read-only view of your database as it was at a certain point in time. Redis supports snapshots, and by default, Redis saves snapshots of the dataset on disk in a binary file called dump.rdb. You can manually call a snapshot, or customize the frequency or change threshold for running the operation.
Here are the two persistence options Redis supports:
RDB stands for “Redis Database Backup”. It is a compact, point-in-time snapshot of the database at a specific time. It takes up less space, maximizes Redis performance, and is good for disaster recovery.
AOF stands for “Append Only File”. AOF keeps track of all the commands that are executed, and in a disastrous situation, it re-execute the commands to get the data back. This method takes more space as all the commands are executed again, and is not a very durable method of snapshotting.
Memcached on the other hand does not support on disk persistence.
Lua is the embedded scripting language for your Redis server, available as of version 2.6, which lets you perform operations inside Redis to simplify your code and increase performance. The two main functions used to evaluate scripts using the Lua interpreter are:
When Lua script is being executed all other requests are blocked as shown in the figure below.
@H_234_304@
Redis also includes Lua scripts debugger in version 3.2 which makes writing complex scripts easier and helps in boosting performance.
Memcached does not support any server-side scripting.
There are two techniques to horizontally scale your Redis database:
You can also vertically scale your Redis setup when you need more memory or compute. It can be done without downtime if you have a HA setup or you use Redis Cluster technology.
The Memcached server doesn’t provide a mechanism to distribute data across nodes (sharding). So, in Memcached, horizontal scalability is as simple as adding more nodes – the problem of partitioning your data into different shards will have to be done on the application/client level. There are some open source tools that can help you with this.
Redis uses TCP as a network protocol and does not support UDP.
Memcached supports both the TCP and UDP communication protocols. Data is sent to the Memcached server in two forms:
Redis supports different types of eviction policies. Let’s take a look at some.
Memcached uses LRU algorithm to evict data when space is required. It First searches for the already expired data to delete if expired data is not available the LRU algorithm is used.
Redis supports Pub/Sub messaging (publish and subscribe). There are three commands that are used for this purpose.
The client uses:
Subscribe and unsubscribe are used to get messages from a specific channel.
The server uses:
The “publish” is used to push data to the clients.
Memcached does not support publish and subscribe messaging.
Redis supports Kafka-like streams with 5.0 or higher version using a new data structure “Redis Streams”. Redis Streams has the concept of consumer groups, like apache Kafka, that lets client applications consume messages in a distributed fashion, making it easy to scale and create highly available systems.
Memcached does not offer native support for Streams, but there are open source library tools like Kafcache for stream processing at low latency.
Redis has a data structure called Geospatial indexes that stores the longitude and latitude data of a location. You can perform different operations on the geospatial data, like calculating the distance between two points or finding nearby places.
Memcached does not have any special data structures to handle geospatial data.
A performance comparison between in-memory key-value data stores is more of an Intellectual exercise than of any practical importance – unless you are deploying systems at such scale that this becomes interesting as a cost-saving measure. This is because such stores are IO bound and usually the network latency might play a Bigger role in application perceived latency than the database latency.
A more practical performance aspect is storage efficiency – how much data can be packed in the same amount of memory. Even here, the internal data structures used by Redis vary based on the data size. So any discussion on performance between these databases should be taken with a pinch of salt.
Let’s take a look at some comparisons shown in a 2016 research paper. In this paper, the authors experiment the widely used in-memory databases to measure their performance in terms of:
Database versions used in the paper:
Database | Version |
---|---|
Redis@H_512_453@ | 3.0.7 |
Memcached | 1.4.14 |
While writing data, as you can see, in the table below Memcached shows exceptional speed even after the number of records moves up to million.
The calculated time to write key-value pairs (ms)
Number of records | ||||
---|---|---|---|---|
Database | 1,000 | 10,000 | 100,000 | 1,000,000 |
Redis | 34 | 214 | 1,666 | 14,638 |
Memcached | 23 | 100 | 276 | 2,813 |
Reading data stays almost consistent in Redis even for a million records but in Memcached as the number of records go up the time also increases a little bit.
The elapsed time to read value corresponding to a given key per database (ms)
Number of records | ||||
---|---|---|---|---|
Database | 1,000 | 10,000 | 100,000 | 1,000,000 |
Redis | 8 | 6 | 8 | 8 |
Memcached | 9 | 14 | 14 | 30 |
While discussing memory usage, Redis is always the best as you can see in the results.
Memory usages of in-memory databases for write operation (MB)
Number of records | ||||
---|---|---|---|---|
Database | 1,000 | 10,000 | 100,000 | 1,000,000 |
Redis | 2.5 | 3.8 | 4.3 | 62.7 |
Memcached | 5.3 | 27.2 | 211 | 264.9 |
As you can see Redis is better than Memcached.
Memory usages of in-memory databases for delete operation (MB)
Number of records | ||||
---|---|---|---|---|
Database | 1,000 | 10,000 | 100,000 | 1,000,000 |
Redis | 0 | 0 | 0 | 0 |
Memcached | 2.2 | 2.1 | 2.2 | 2.2 |
The greater popularity and community for Redis has also driven the need for managed services, hosting and support. Popular managed database providers for Redis™* include ScaleGrid, Redis Labs, AWS Elasticache, Azure Cache and DigitalOcean. This page provides a great comparison of the top providers for Redis™. Redis also has extensive internal reporting tools like cache hits, memory usage, ops, and even a slow query logged.
Managed services for Memcached are far less available, but is still supported through Amazon Elasticache.
Redis has native TLS support starting Redis 6.0. Earlier versions of Redis recommended the use of stunnel for providing TLS support.
Memcached 1.5.13 and above versions support authentication and encryption via TLS. This feature is still in experimental stages.
Up to Redis 5.x, Redis only supported a simple password based authentication. This password was stored in plaintext on the server. Redis in version 6.0 onwards supports a fully featured ACL.
Memcached version 1.4.3 and greater has SASL support. Previously Memcached had no authentication layer.
Redis and Memcached are both great and have applications in different areas. Redis being developed later has many advanced functionalities and has great documentation and community.
以上是脚本宝典为你收集整理的Redis vs. Memcached – 2021 Comparison全部内容,希望文章能够帮你解决Redis vs. Memcached – 2021 Comparison所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。