lettuce is a free, open source databases project written in Java and released under MIT. It has 5,778 GitHub stars, 1,101 forks and 204 open issues, and was last pushed 3 hours ago. On this registry it ranks #109 of 143 tracked projects in Databases, with 5 head-to-head comparisons available.

What is lettuce?

Lettuce is an MIT-licensed, thread-safe Java Redis client from the Redis organization that speaks to Redis over synchronous, asynchronous, and reactive APIs, and it is aimed at Java teams running Redis or Redis-compatible caches such as AWS ElastiCache and Azure Redis Cache.

What it is

Lettuce is a scalable, thread-safe Redis client for Java, built on the Netty event-loop and networking framework. It exposes three programming models over the same connection: a synchronous API, an asynchronous API, and a reactive API, and it supports advanced Redis topologies and features including Redis Sentinel, Redis Cluster, Pipelining, Auto-Reconnect, and the Redis data models. The client also covers protocol and connection details such as SSL connections, Unix Domain Socket connections, a Streaming API, Codecs for UTF8, bit, and JSON representations of data, multiple Command Interfaces, and support for Native Transports. This version has been tested against the latest Redis source-build, and it is compatible with Java 8 and later, shipping as an implicit automatic module without descriptors.

The concrete problem it replaces is hand-rolled or thread-bound Redis access in JVM services. Rather than forcing a connection per thread or a pool discipline that has to be managed around every call, Lettuce lets multiple threads share one connection, provided those threads avoid blocking and transactional operations such as BLPOP and MULTI/EXEC. In the Java ecosystem that means a team writes its Redis access against one client library that scales with the application's concurrency model instead of against connection management code that has to be tuned and repaired per service.

Key capabilities

  • Synchronous, asynchronous, and reactive APIs over a single shared connection, so an application can mix blocking calls, CompletableFuture-style results, and reactive streams without a second client.
  • Redis Sentinel and Redis Cluster support for high-availability and sharded deployments, configured through the client rather than through bespoke routing code.
  • Pipelining, which batches commands without waiting for individual replies, plus Auto-Reconnect to re-establish connections after a failure.
  • SSL connections and Unix Domain Socket connections for encrypted or host-local access.
  • Codecs for UTF8, bit, and JSON representations of data, controlling how keys and values are serialized onto the wire.
  • Streaming API and multiple Command Interfaces, for consuming Redis Streams and for choosing how commands are expressed in code.
  • Support for RediSearch, RedisJSON, and Redis Vector Sets, extending the client beyond core Redis commands.

Who uses it and how

  • JVM services that must serve many concurrent requests against one Redis connection rather than paying for a connection per thread.
  • Applications deployed against managed Redis endpoints, indicated by the aws-elasticache and azure-redis-cache topics, where the client handles topology and failover rather than application code.
  • Sharded or replicated production deployments using Redis Cluster or Redis Sentinel for failover.
  • Teams building reactive or asynchronous pipelines, using the reactive and asynchronous topics to match the client to a non-blocking application stack.
  • Applications that store structured values, using JSON codecs and RedisJSON, or that run search and vector workloads through RediSearch and Redis Vector Sets.

Getting started

Add the Maven Central artifact io.lettuce:lettuce-core to a build — dependency information is published for Maven, Ivy, Gradle, and other build tools — or download a release from the project's Releases page. Reference documentation lives at https://redis.github.io/lettuce/ and the Javadoc at https://www.javadoc.io/doc/io.lettuce/lettuce-core/latest/index.html.

How it compares

This registry entry provides no list of paid products that Lettuce replaces and names no comparable Java Redis clients, so on the facts available it stands alone here rather than sitting in a documented head-to-head set. What is certain from the licence field and README is that it is MIT-licensed open source from the Redis organization itself, with no cost model, seat count, or hosted-service dependency attached, and it can be pointed at any Redis endpoint the operator controls, including self-managed clusters and cloud caches.

When to use it — and when not to

Choose Lettuce when a Java service needs one thread-safe client with synchronous, asynchronous, and reactive access and support for Cluster or Sentinel. Operators take on the Redis deployment itself — servers, topology, failover configuration, and any TLS material for SSL connections — because the client carries no bundled database, storage layer, or mail service. Teams that only make a handful of blocking calls and cannot rely on the shared-connection rule for blocking or transactional commands such as BLPOP and MULTI/EXEC should confirm their usage pattern fits before adopting it, and the 204 open issues are worth reviewing for known rough edges in the areas being used.

project readme (upstream, from github) — read inline

Lettuce - Advanced Java Redis client

Integration codecov MIT licensed Maven Central Javadocs

Discord Twitch YouTube Twitter Stack Exchange questions

Lettuce is a scalable thread-safe Redis client for synchronous, asynchronous and reactive usage. Multiple threads may share one connection if they avoid blocking and transactional operations such as BLPOP and MULTI/EXEC. Lettuce is built with netty. Supports advanced Redis features such as Sentinel, Cluster, Pipelining, Auto-Reconnect and Redis data models.

This version of Lettuce has been tested against the latest Redis source-build.

See the reference documentation and API Reference for more details.

How do I Redis?

Learn for free at Redis University

Try the Redis Cloud

Dive in developer tutorials

Join the Redis community

Work at Redis

Documentation

Binaries/Download

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at http://search.maven.org.

Releases of lettuce are available in the Maven Central repository. Take also a look at the Releases.

Example for Maven:

<dependency>
  <groupId>io.lettuce</groupId>
  <artifactId>lettuce-core</artifactId>
  <version>x.y.z</version>
</dependency>

If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare the appropriate dependency version.

<dependency>
  <groupId>io.lettuce</groupId>
  <artifactId>lettuce-core</artifactId>
  <version>x.y.z.BUILD-SNAPSHOT</version>
</dependency>

<repositories>
  <repository>
    <id>sonatype-snapshots</id>
    <name>Sonatype Snapshot Repository</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </repository>
</repositories>

Basic Usage

RedisClient client = RedisClient.create("redis://localhost");
StatefulRedisConnection<String, String> connection = client.connect();
RedisStringCommands sync = connection.sync();
String value = sync.get("key");

Each Redis command is implemented by one or more methods with names identical to the lowercase Redis command name. Complex commands with multiple modifiers that change the result type include the CamelCased modifier as part of the command name, e.g. zrangebyscore and zrangebyscoreWithScores.

See Basic usage for further details.

Asynchronous API

StatefulRedisConnection<String, String> connection = client.connect();
RedisStringAsyncCommands<String, String> async = connection.async();
RedisFuture<String> set = async.set("key", "value");
RedisFuture<String> get = async.get("key");

LettuceFutures.awaitAll(set, get) == true

set.get() == "OK"
get.get() == "value"

See Asynchronous API for further details.

Reactive API

StatefulRedisConnection<String, String> connection = client.connect();
RedisStringReactiveCommands<String, String> reactive = connection.reactive();
Mono<String> set = reactive.set("key", "value");
Mono<String> get = reactive.get("key");

set.subscribe();

get.block() == "value"

See Reactive API for further details.

Pub/Sub

RedisPubSubCommands<String, String> connection = client.connectPubSub().sync();
connection.getStatefulConnection().addListener(new RedisPubSubListener<String, String>() { ... })
connection.subscribe("channel");

Building

Lettuce is built with Apache Maven. The tests require multiple running Redis instances for different test cases which are configured using a Makefile. Tests run by default against Redis latest.

To build:

$ git clone https://github.com/redis/lettuce.git
$ cd lettuce/
$ make start
  • Run the build: make test
  • Start Redis (manually): make start
  • Stop Redis (manually): make stop
  • Clean up: make clean

Bugs and Feedback

For bugs, questions and discussions please use the GitHub Issues.

License

Contributing

Github is for social coding: if you want to write code, I encourage contributions through pull requests from forks of this repository. Create Github tickets for bugs and new features and comment on the ones that you are interested in and take a look into CONTRIBUTING.md

Frequently asked questions

Is lettuce free to use?

lettuce is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does lettuce do?

Advanced Java Redis client for thread-safe sync, async, and reactive usage. Supports Cluster, Sentinel, Pipelining, and codecs.

What is lettuce written in?

lettuce is primarily written in Java. Its source is publicly available at https://github.com/redis/lettuce, and it has 5,778 GitHub stars.