Redis vs Memcached: Which In‑Memory Database Fits Your Backend?

This article compares Redis and Memcached across thread models, data structures, eviction policies, pipelines, persistence, high availability, and clustering, helping developers choose the most suitable in‑memory database for their specific workload and performance requirements.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Redis vs Memcached: Which In‑Memory Database Fits Your Backend?

Introduction

Redis and Memcached are both in‑memory databases known for extremely fast access speeds, but they differ in many aspects that affect how they should be used in development.

Thread Model

Memcached uses a multithreaded model with I/O multiplexing; the main thread distributes requests to worker threads, allowing concurrent handling but incurring context‑switch overhead and lock contention.

Redis also uses I/O multiplexing but processes requests in a single thread, avoiding context switches and lock contention but blocking the entire server when a request takes long to complete. Redis’s performance bottleneck is therefore memory and network bandwidth rather than CPU.

Strictly speaking, Redis’s single thread handles request processing, while other internal threads handle asynchronous tasks. Redis 6.0 adds multithreading for network I/O to improve performance.

Data Structures

Memcached supports only string values, limited to 1 MB and a maximum TTL of 30 days.

Redis offers a rich set of data types: string, list, hash, set, sorted set, geo, and HyperLogLog, providing flexible operations for various use cases.

Eviction Policies

Memcached enforces a global memory limit and uses an LRU eviction strategy, which can prematurely evict newly written data due to its memory management design.

Redis does not require a fixed memory limit and provides multiple eviction policies, including volatile‑lru, allkeys‑lru, volatile‑random, allkeys‑random, volatile‑ttl, volatile‑lfu, and allkeys‑lfu, allowing selection based on business scenarios.

Pipelines and Transactions

Redis supports pipelining, enabling a client to batch multiple commands in a single network round‑trip, reducing latency.

Redis also offers a lightweight transaction mechanism that ensures a batch of commands executes atomically and in order, aborting the whole transaction if a watched key changes.

Persistence

Memcached does not provide data persistence; a crash results in total data loss.

Redis supports two persistence methods: RDB (snapshotting) and AOF (append‑only file), which can be combined to guarantee data durability.

High Availability

Memcached lacks built‑in replication; it operates as a single node, requiring application‑level handling of node failures.

Redis offers master‑slave replication, Sentinel for automatic failover, and read/write splitting to improve availability and performance.

Clustering

Both systems can run in clusters, but their mechanisms differ.

Memcached relies on client‑side consistent hashing; when a node fails, other nodes absorb its load.

Redis clusters assign hash slots to nodes, each with at least one replica, and support both the official Redis Cluster and third‑party proxy‑based solutions like Codis and Twemproxy.

Conclusion

Redis provides a richer feature set with comparable performance to Memcached, making it the preferred choice for most modern applications that require diverse data structures, persistence, and high availability. Memcached remains suitable for simple, high‑throughput key/value use cases with minimal memory requirements.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

rediscachingIn-Memory DatabaseMemcached
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.