Redis vs Memcached
Redis and Memcached are two similar data-storage systems. Redis is an open source in-memory key value store, whereas Memcached is a high-performance distributed-memory system. Both systems hold most data in memory and support various operations. Here is a head-to-head comparison of Redis vs Memcached:
Memcached is a simple cache server that allows for storing key-value pairs with a string limit of 1MB. While Memcached does this extremely well, it is basically a one-trick pony without third-party tools. All data is lost when Memcached is restarted, so it should not be used to store important data.
Redis can outperform Memcached in all categories. While the system can be used as a cache, Redis can store key-value pairs up to 512MB. As persistence is the default option, data will not be lost on restart, unless the Redis default setting is intentionally changed. Redis’s speed is limited only by system resources, such as bandwidth. Redis also has much wider support that Memcached and has also become the front runner in third-party applications.
Both programs are useful as a cache and are fast and powerful enough to handle most data-storage needs. Standards will vary due to several factors, such as program version and workload, but the two programs score similarly on speed.
With Memcached the user must specify the cache size and the daemon quickly fills up as items are inserted. There is no way of reclaiming any of the used space without restarting the program. Memcached will still use the full amount of RAM it was configured with, even after the database is flushed. With Memcached the user is stuck with the initially-defined memory parameters.
Redis allows for more flexibility, allowing the user to set the maximum size. Redis only uses the memory it needs and will return memory it no longer requires. For example, storing 200MB of data will see the Memcached RAM usage grow to 225MB, whereas Redis RAM usage will grow to 228MB. However, after flushing both databases Memcached memory usage remained at 225MB, while Redis’s dropped to 29MB. Both programs are efficient at storing data, but only Redis can reclaim it. When comparing Redis vs Memcached for speed, Redis win hands down.
Disk Input and Output Dumping
As it dumps to disk by default, with a highly configurable persistence, this is an easy win for Redis. Third-party tools must be used to dump to disk with Memcached.
Both programs provide ample headroom before more than a single-instance cache is needed. However, Redis includes the needed tools that allow for exceeding the limit, whereas Memcached has no such integrated function.
Redis has better documentation than Memcached and has twice the stackoverflow results as Memcached.
Redis persists data to disk with “snapshotting” and will write all data to disk with virtually no drop in performance, provided there is enough available RAM. Redis has several configuration options that allow persistence to be fine tuned. Memcached cannot perform any of these functions.
Multiple Data Types
Whereas Memcached is limited to strings, Redis can serve up various data types.
Binary values and strings have an upper limit of 512MB in Redis, whereas Memcached strings are limited to just a single MB. Redis provides more standard tools for working with this datatype, such as bit-level manipulation and multi-key operations, whereas Memcached provides none.
Redis hash commands can map between the string fields and string values and are useful for logically grouping numerous keys, such as obtaining, expiring or deleting all the members together. For example, a hash can store user profiles between applications and save the user ID as the key that allows for storing as much data as needed about a user under a single key.
Redis lists are a sequential collections of strings optimized for inserting, reading, or removing values, leveraging lists and perform range queries. No such luck with Memcached.
Redis provides commands to manage sets, whereas Memcached does not. Sets are important for managing things like unique visitor trackers and access-control lists. Again, Memcached leaves users lacking.
Unlike Memcached, Redis provides commands for analyzing geographic data, such as radius distances queries.
Redis offers pipelining that allows for executing multiple Redis commands at once, instead if individually. This allows for improved throughput on bulk actions that would require the execution of several individual commands.
Examining a head-to-head comparison of Redis vs Memcached, Memcached can cannot perform the vast majority of the functions that Redis can and Redis is superior wherever their functions overlap. Redis is much more powerful and has far better support than Memcached. Additionally, with Redis’s popularity, the program’s features and support should only continue to expand in the years to come.
This article contains far from a comprehensive list of all the features and benefits that Redis has over Memcached. However, with just the comparisons made here, when comparing Redis vs Memcached the choice seems pretty clear. While Memcached is a rock-solid program for doing what it was designed to do, because of its versatility and flexibility, Redis wins hands down over Memcached for any projects not already dependent on Memcached.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.Get Started