DEV Community

Cover image for Redis VS Memcached for cache
Tanmoy Sarkar
Tanmoy Sarkar

Posted on

Redis VS Memcached for cache

Redis :

Redis is an open-source, in-memory data structure store, used as a database, cache, and message broker.

Memcached:

Memcached is a distributed, high-performance, in-memory caching system. It is used to temporarily store and serve frequently requested data from memory.


The similarity between Redis and Memcached

  • Both are key-value storage

  • Both system store data in memory or RAM

  • Both Redis and Memcached are capable of running on multiple servers


Data structure

  • Redis: This supports various ranges of data types based on the additional module and some built-in support. Some data types: strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlog, and geospatial indexes with radius queries

  • Memcached: This support only string as the value in key-value entry


Transactions

  • Memcached doesn't support transactions, although its operations are atomic.

  • Redis provides out-of-the-box support for transactions to execute commands.


Architecture

  • Redis uses a single-core architecture.

  • Memcached implements a multi-threaded architecture by utilizing multiple cores.


Is there any speciality in Redis?

I know this portion is a little bit out of topic. But I have seen, in many blogs or youtube videos, shows redis is the key-value store only to just cache or temporary database.

So let's know a little bit about the full potential of Redis.

redis modules

By enabling different modules, we can achieve the full potential

  • RedisJSON to store JSON database directly in Redis.

  • RedisGraph is a graph database built on Redis. This graph database uses GraphBlas under the hood for its sparse adjacency matrix graph representation.

  • RedisSearch is a high-performance, full-text search engine that is built as a Redis module, offering efficient indexing and querying capabilities for text-based data within Redis.

  • RedisTimeSeries is a Redis module for efficiently storing and querying time-series data, providing functionality for querying and analyzing time-stamped data, such as metrics, events, and logs.

  • RedisBloom is a Redis module that provides scalable probabilistic data structures, such as Bloom filters, counting filters, and others, to support high-performance and memory-efficient data analysis and storage operations.

After seeing the modules and capability of Redis, we can only think of this

meme on redis's capability


Now, what is best for caching?

Here we need to think about the data structure.

The best case to use Memcached over Redis

  • The cached data format is plain string data to cache like HTML pages, CSS, JS or anything other than that.

  • The dataset size is going to be very large in future

If these two conditions are satisfied then it will be best to go with Memcached.

In other cases, you can go with Redis.


We have reached the end of this blog.

hi-fi to users

Top comments (0)