logo

Valkey vs Redis vs Memcached

While Redis and Memcached have been long-standing competitors, Valkey is a new, community-driven open-source fork of Redis, created in response to changes in Redis's licensing.

TL;DR

Feature Memcached Redis Valkey
Primary Goal Simple, fast caching Multi-purpose data structure server Community-driven evolution of Redis
Data Model Simple Key-Value (strings) Advanced Data Structures Advanced Data Structures (same as Redis)
Persistence None (in-memory only) RDB snapshots and AOF logs RDB snapshots and AOF logs
Replication None built-in (third-party) Primary-Replica Primary-Replica
Clustering None built-in (client-side) Redis Cluster Redis Cluster (initially)
Extensibility Limited Lua scripting, Modules Lua scripting, Modules
Threading Model Multi-threaded Single-threaded (event loop) Multi-threaded (initially)
License BSD Source-Available (SSPL/RSAL) BSD (Community Governed)

Detailed Comparison

1. Core Philosophy and Origins

  • Memcached: The original high-performance, distributed memory caching system. Its design philosophy is simplicity and speed. It does one thing and does it exceptionally well: serve as a transient cache for simple string data.
  • Redis: Started as a more powerful alternative to Memcached. Its philosophy is to be a versatile, multi-purpose "data structure server." It's not just a cache but can act as a database, message broker, and more, thanks to its rich feature set.
  • Valkey: A direct response to Redis Inc. changing the license of the Redis core repository from the open-source BSD to the source-available SSPL and RSAL. Valkey is a community-governed, open-source fork of Redis. Its goal is to continue the development of Redis under the open-source BSD license, ensuring it remains free to use, modify, and distribute without the restrictions of the new licenses. It is backed by major tech companies like AWS, Google Cloud, and Oracle.

2. Data Structures

This is a major point of differentiation.

  • Memcached: Simple key-value store. The values are treated as opaque strings. You can set, get, and delete keys.
  • Redis: Supports a rich set of advanced data structures in memory. This allows for more complex operations to be offloaded from the application to the data store. Key data types include:
    • Strings: Similar to Memcached.
    • Lists: Ordered sequences of strings.
    • Sets: Unordered collections of unique strings.
    • Hashes: Maps of field-value pairs.
    • Sorted Sets: Sets where each member has a score, allowing for ranking and ordering.
    • Bitmaps & HyperLogLogs: For space-efficient, large-scale analytics.
    • Streams: An append-only log for event-driven architectures.
  • Valkey: As a fork of Redis, it inherits all of Redis's advanced data structures. Its development path will likely see these structures evolve and new ones added over time.

3. Persistence

  • Memcached: No persistence. It is a pure in-memory cache. If a server restarts or crashes, all the data it held is lost.
  • Redis & Valkey: Both offer robust persistence options, making them suitable for use as a primary database:
    • RDB (Snapshotting): Creates point-in-time snapshots of the dataset at specified intervals.
    • AOF (Append-Only File): Logs every write operation. This provides better durability than RDB.

4. Scalability and High Availability

  • Memcached: Client-side clustering. It does not have built-in replication or clustering. To scale out, you must implement sharding logic in your application client, which distributes keys across multiple Memcached instances.
  • Redis & Valkey: Provide built-in solutions for scalability and high availability:
    • Primary-Replica Replication: A primary instance can have one or more replicas that contain a copy of the data, allowing for read scaling and failover.
    • Clustering: Redis Cluster provides automatic sharding, allowing you to scale writes and dataset size horizontally across multiple nodes. Valkey inherits this functionality.

5. Multi-Threading

  • Memcached: Multi-threaded. It can utilize multiple CPU cores to handle many concurrent connections, which can be advantageous for high-throughput caching workloads.
  • Redis: Primarily single-threaded, using an event loop model. This simplifies the data model and avoids race conditions, but it can be a bottleneck on multi-core machines. Newer versions of Redis have introduced I/O threading to offload network operations to other threads.
  • Valkey: Has announced plans to introduce a more threaded model to improve performance on modern hardware, which could become a key differentiator from Redis in the future.

Which One Should You Use?

  • Choose Memcached if:
    • You need a simple, high-throughput, transient cache.
    • Your data is unstructured string data.
    • You are comfortable with implementing scaling logic on the client side.
    • You do not need any persistence or advanced features.
  • Choose Redis if:
    • You need advanced data structures and atomic operations on them.
    • You require data persistence for durability.
    • You need built-in replication and clustering for high availability and scalability.
    • You are building more than just a cache (e.g., a real-time leaderboard, message queue, or session store).
    • Your project's licensing is compatible with the SSPL or RSAL.
  • Choose Valkey if:
    • You want the power and features of Redis but need to use a permissive, open-source license (BSD).
    • You want to be part of a community-driven project backed by major industry players.
    • You are starting a new project and want to avoid any future licensing complexities associated with Redis.
    • You are interested in its future development direction, particularly around improved multi-threading.