Although Memcached and Redis have a lot in common, each has some unique features too. We will focus on the most important ones here.
Architecture: Memcached is multi-threaded, which means it can use multiple processing cores simultaneously. Redis on the other hand uses a single core. This makes it more efficient at handling small amounts of data. For very large amounts of data, however, Memcached is the better option.
Data types:Memcached can only handle simple strings of up to 1 MB, whereas Redis supports values up to 512 MB in size and more complex data structures like lists, hashes, streams, sets, sorted sets, bitmaps, and hyperloglogs. What’s more, Redis can also measure and store geospatial data.
Data persistence: Unlike Memcached, Redis is not simply an in-memory system. With Memcached, if there is no more space on a server for new items, the least recently used data will automatically be deleted. Data is also lost if a Memcached instance fails. With Redis on the other hand, data can be restored using the “point-in-time” snapshot function or Append Only File (AOF) mode. Note however, that AOF mode may slow things down slightly.
Cluster management: Redis uses both client-side and server-side caching to distribute data, whereas Memcached only uses client-side caching. The nodes in a Redis cluster can exchange data with one another. There is no notable impact on response times if a node subset fails. In Memcached this kind of data exchange is not possible at all.
Transactions: Both in-memory systems use what are known as “atomic commands”. This means that when values are entered, they are instantaneously displayed on the client side. In Redis, commands can also be grouped together in the form of isolated atomic operations. This feature, called pipelining, means that Redis can respond to multiple commands at the same time. This is not the case in Memcached.
Pub/Sub: Redis supports the Pub/Sub architecture. This messaging pattern facilitates efficient communication between applications. It is used for high-performance chat rooms, live streams, social media feeds, and communication between different servers.
Lua scripting: If developers want to use Redisto perform complex calculations, they can use Lua scripts. Lua is a lightweight programming language into which new logic can easily be added. This boosts performance and simplifies applications.