What is Valkey?
Valkey is an open-source, high-performance, in-memory database. The Valkey project is a fork of the now-discontinued open-source version of Redis. Like Redis, Valkey can be used for caching, pub/sub messaging, and many more demanding applications.
If you’re wondering how Valkey compares to Redis and other databases and data stores, this article will cover everything you need to know. It also covers how Java developers can use third-party clients to take advantage of Valkey’s features and benefits.
What Is Valkey?
In March 2024, Redis Inc. announced that starting with Redis 7.4, it would only maintain and distribute the enterprise version of its flagship database product. Up to that point, Redis Inc. had always maintained both the enterprise version and the open-source Redis OSS. In response to this news, the Linux Foundation and a group of developers from the Redis community forked version 7.2 of Redis OSS to create the new Valkey project. Therefore, long-time Redis users will be very comfortable with Valkey.
Like Redis, Valkey is not a traditional key-value database but rather a data structure store. This is an important distinction, as a key in Valkey can be a string, as with other databases, but it can also be a more complex data structure like a list, set, hash, bit array, or stream. Developers can take advantage of this flexibility for a wide range of Valkey use cases, such as:
- Lightweight non-relational database: Valkey can be used as a non-relational key-value database with an extremely lightweight memory footprint. For example, a database with one million small keys (such as strings) only occupies 85 megabytes of memory.
- Cache: Valkey's ability to store arbitrary data can be leveraged to create a highly available cache, significantly reducing latency and increasing throughput.
- Message broker: Valkey supports the publish/subscribe (pub/sub) messaging pattern, making it a high-performance message broker. Pub/sub, when combined with Valkey's pattern-matching capabilities and flexible data structures like lists, sorted sets, and hashes, supports high-performance real-time applications like chat rooms, social media feeds, and server-to-server communication.
- Streaming media: Valkey's high-performance in-memory data store can handle the demanding requirements of live streaming, efficiently storing and retrieving metadata like user profiles, viewing histories, and authentication tokens for millions of concurrent users.
With many developers from the open source community who have spent years contributing to Redis onboard, Valkey has quickly become one of the most widely used databases in the world.
How Does Valkey Work?
Valkey works by storing keys that map to one of five different data structures:
- STRING
- LIST
- SET
- HASH
- ZSET (sorted set)
Some Valkey commands are shared among all five data structures, while others are only used by one or two.
Valkey Benefits and Features
- Low latency, high throughput: Valkey's in-memory architecture eliminates the need for disk I/O, significantly reducing latency and increasing throughput for both read and write operations. With microsecond response times, Valkey can handle millions of operations per second.
- High availability and reliability: Valkey's primary replica architecture ensures data redundancy and fault tolerance, minimizing downtime and the potential for data loss. Valkey can replicate data across multiple nodes with support for asynchronous replication, improving read performance.
- Scalability: Valkey supports multiple clustering scenarios, allowing it to scale as needed for peak loads or an application’s increasing demands.
Valkey Comparison
While Valkey isn't the only option available in the database and caching space, it stands out among alternatives like Hazelcast, Apache Ignite, and Memcached.
Unlike Memcached, which is limited to basic string storage, Valkey offers a versatile range of data structures. It can automatically persist data to disk using AOF or RDB, provide granular control over cache eviction, and employ replication for high availability.
Compared to Hazelcast and Apache Ignite, Valkey offers a richer ecosystem of Java distributed objects and collections through third-party clients like Redisson.
Technically, Valkey's single-threaded architecture simplifies development and avoids "split brain" scenarios, while Hazelcast's multi-threaded nature can introduce complexity. Valkey's efficient memory management using jemalloc provides performance advantages over Hazelcast's heap-based storage, especially for larger datasets.
Valkey Java Clients
While Valkey is clearly a powerful database, it becomes even more impactful for Java developers when combined with a full-featured third-party client like Redisson.
While Valkey itself doesn't directly integrate with Java, Redisson bridges the gap, providing a comprehensive suite of Java objects and collections. This enables developers to leverage Valkey's capabilities seamlessly within their Java applications.
Redisson's versatility extends beyond basic integration. It supports asynchronous, reactive, and RxJava2 programming models, making it compatible with modern development practices. Additionally, its integration with popular Java frameworks like Spring, JCache, Hibernate, and Apache Tomcat streamlines development workflows.
When compared to other Valkey Java clients like Jedis and Lettuce, Redisson PRO is the clear winner. It offers significantly faster performance in common operations such as HSET, RPUSH, SADD, SET, and INCR.
To learn more about the premier Java client for Valkey, visit the Redisson PRO website today.