{
  "schema_version": 2,
  "id": "develop/clients/lettuce",
  "title": "Lettuce guide (Java)",
  "url": "https://redis.io/docs/latest/develop/clients/lettuce/",
  "summary": "Connect your Lettuce application to a Redis database",
  "aliases": [
    "/develop/connect/clients/java/lettuce",
    "/connect/clients/lettuce/",
    "/clients/lettuce/",
    "/develop/clients/java/lettuce/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-09T09:47:45+01:00",
  "children": [
    {
      "id": "develop/clients/lettuce/connect",
      "summary": "Connect your Java application to a Redis database",
      "title": "Connect to the server",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/connect/"
    },
    {
      "id": "develop/clients/lettuce/amr",
      "summary": "Learn how to authenticate to an Azure Managed Redis (AMR) database",
      "title": "Connect to Azure Managed Redis",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/amr/"
    },
    {
      "id": "develop/clients/lettuce/queryjson",
      "summary": "Learn how to use Redis Search with JSON and hash documents.",
      "title": "Index and query documents",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/queryjson/"
    },
    {
      "id": "develop/clients/lettuce/vecsearch",
      "summary": "Learn how to index and query vector embeddings with Redis",
      "title": "Index and query vectors",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/vecsearch/"
    },
    {
      "id": "develop/clients/lettuce/transpipe",
      "summary": "Learn how to use Redis pipelines and transactions",
      "title": "Pipelines and transactions",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/transpipe/"
    },
    {
      "id": "develop/clients/lettuce/vecsets",
      "summary": "Index and query embeddings with Redis vector sets",
      "title": "Vector set embeddings",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/vecsets/"
    },
    {
      "id": "develop/clients/lettuce/prob",
      "summary": "Learn how to use approximate calculations with Redis.",
      "title": "Probabilistic data types",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/prob/"
    },
    {
      "id": "develop/clients/lettuce/failover",
      "summary": "Improve reliability using the failover features of Lettuce.",
      "title": "Client-side geographic failover",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/failover/"
    },
    {
      "id": "develop/clients/lettuce/produsage",
      "summary": "Get your Lettuce app ready for production",
      "title": "Production usage",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/produsage/"
    },
    {
      "id": "develop/clients/lettuce/error-handling",
      "summary": "Learn how to handle errors when using Lettuce.",
      "title": "Error handling",
      "url": "https://redis.io/docs/latest/develop/clients/lettuce/error-handling/"
    }
  ],
  "page_type": "content",
  "content_hash": "1064c2efbb305d04a9e0733103061e38384d9e4d3e1b0f5eb4909cd84a4692a4",
  "sections": [
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "To include Lettuce as a dependency in your application, edit the appropriate dependency file as shown below.\n\nIf you use Maven, add the following dependency to your `pom.xml`:\n\n[code example]\n\nIf you use Gradle, include this line in your `build.gradle` file:\n\n[code example]\n\nIf you wish to use the JAR files directly, download the latest Lettuce and, optionally, Apache Commons Pool2 JAR files from Maven Central or any other Maven repository.\n\nTo build from source, see the instructions on the [Lettuce source code GitHub repo](https://github.com/lettuce-io/lettuce-core)."
    },
    {
      "id": "connect-and-test",
      "title": "Connect and test",
      "role": "content",
      "text": "Connect to a local server using the following code. First, import\nthe required classes.\n\nFoundational: Import required Lettuce classes for synchronous Redis connections\n\n**Difficulty:** Beginner\n\n**Available in:** Java\n\n##### Java\n\n[code example]\n\n\n\nUse the following code to connect to the server.\n\nFoundational: Establish a synchronous connection to a Redis server using Lettuce\n\n**Difficulty:** Beginner\n\n**Available in:** Java\n\n##### Java\n\n[code example]\n\n\n\nTest the connection by storing and retrieving a simple string.\n\nFoundational: Set and retrieve string values using SET and GET commands to verify the connection works\n\n**Difficulty:** Beginner\n\n**Available in:** Java\n\n##### Java\n\n[code example]\n\n\n\nClose the connection when you're done.\n\nFoundational: Properly close the Lettuce connection to release resources\n\n**Difficulty:** Beginner\n\n**Available in:** Java\n\n##### Java\n\n[code example]"
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "The [Lettuce reference guide](https://redis.github.io/lettuce/) has more examples\nand an API reference. You may also be interested in the\n[Project Reactor](https://projectreactor.io/) library that Lettuce uses.\n\nSee also the other pages in this section for more information and examples:"
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "xml",
      "code": "<dependency>\n    <groupId>io.lettuce</groupId>\n    <artifactId>lettuce-core</artifactId>\n    <version>6.7.1.RELEASE</version> <!-- Check for the latest version on Maven Central -->\n</dependency>",
      "section_id": "install"
    },
    {
      "id": "install-ex1",
      "language": "plaintext",
      "code": "dependencies {\n    compileOnly 'io.lettuce:lettuce-core:6.7.1.RELEASE'\n}",
      "section_id": "install"
    },
    {
      "id": "connect-and-test-ex0",
      "language": "java",
      "code": "import io.lettuce.core.*;\nimport io.lettuce.core.api.StatefulRedisConnection;\nimport io.lettuce.core.api.sync.RedisCommands;",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex1",
      "language": "java",
      "code": "RedisURI uri = RedisURI.Builder\n                .redis(\"localhost\", 6379)\n                .build();\n\n        RedisClient client = RedisClient.create(uri);\n        StatefulRedisConnection<String, String> connection = client.connect();\n        RedisCommands<String, String> commands = connection.sync();",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex2",
      "language": "java",
      "code": "commands.set(\"foo\", \"bar\");\n        String result = commands.get(\"foo\");\n        System.out.println(result); // >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex3",
      "language": "java",
      "code": "connection.close();\n        client.shutdown();",
      "section_id": "connect-and-test"
    }
  ]
}
