#1
Redis is a popular in-memory data store, commonly used for caching, pub/sub messaging, and real-time analytics. Integrating Redis with Quarkus is straightforward—especially when you're using Docker for development and Kubernetes in production. With Quarkus supporting profile-based configurations in YAML (application.yml), you can keep your setup clean and environment-specific.
In this guide, you'll learn how to configure Redis in Quarkus using Docker for local dev and Kubernetes ConfigMaps and Secrets for production, all managed via profile-specific YAML files.

1. Add Required Dependencies

Before getting started, ensure that your Quarkus project includes the necessary dependencies. If you're using Redis as a cache or simple client, include the following in your pom.xml:
<dependencies>
  <!-- Redis Client -->
  <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-redis-client</artifactId>
  </dependency>

  <!-- Kubernetes Config Support -->
  <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-kubernetes-config</artifactId>
  </dependency>

  <!-- YAML Configuration Support -->
  <dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-config-yaml</artifactId>
  </dependency>
</dependencies>
These dependencies give you Redis support and the ability to read YAML configuration files and Kubernetes config values.

2. Running Redis with Docker (Dev Setup)

You can spin up a local Redis container with a single command:
docker run --name redis-dev -p 6379:6379 -d redis:latest
This command launches a Redis instance accessible at localhost:6379.

3. Configure application-dev.yml

Create a file named application-dev.yml in the src/main/resources directory. This file will hold Redis configuration specific to your development profile:
"%dev":
  quarkus:
    redis:
      hosts: redis://localhost:6379
      timeout: 10s
This tells Quarkus to connect to the locally running Redis instance via the standard Redis URI.
To run the app in development mode with this profile:
./mvnw quarkus:dev -Dquarkus.profile=dev

4. Setting Up Redis for Production with Kubernetes

In production, it's best practice to externalize configuration. Kubernetes ConfigMaps and Secrets allow you to pass connection details securely to your app.

4.1: Create a Redis ConfigMap

This ConfigMap stores non-sensitive Redis configuration:
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
  namespace: your-namespace
data:
  redis.hosts: redis://redis-service:6379
Replace redis-service with your actual Redis service hostname in your cluster.

4.2: (Optional) Create a Secret

If your Redis instance requires authentication, store the password in a Secret:
apiVersion: v1
kind: Secret
metadata:
  name: redis-secret
  namespace: your-namespace
type: Opaque
data:
  redis.password: cmVkaXNwYXNz  # base64 for 'redispass'

5. Configure application-prod.yml

Now create a file named application-prod.yml with production-specific config using environment placeholders:
"%prod":
  quarkus:
    redis:
      hosts: ${redis.hosts}
      password: ${redis.password}
      timeout: 10s
    kubernetes-config:
      enabled: true
      config-maps: redis-config
      secrets: redis-secret
This setup ensures Quarkus loads Redis configuration from the Kubernetes ConfigMap and Secret during startup.

6. Deploy to Kubernetes with the Right Profile

In your Kubernetes Deployment manifest, make sure you pass the correct profile:
env:
  - name: QUARKUS_PROFILE
    value: prod
This tells Quarkus to activate the prod profile and apply the values from application-prod.yml.

7. Validating the Setup

To ensure your Quarkus application is connecting to Redis properly, you can inject the Redis client and perform a simple ping:
import io.quarkus.redis.client.RedisClient;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/health")
public class RedisHealthResource {

    @Inject
    RedisClient redisClient;

    @GET
    public String checkRedis() {
        return redisClient.ping();
    }
}
Access /health to verify that Redis is responding.

image quote pre code