Example

Cache Redis

Demonstrates how to cache application data in Redis with helix-cache-redis. Shows RedisCacheService, JedisPool, JSON value serialization, Redis key prefixes and TTLs, plus cache hits, misses, and explicit eviction.
Group
REST API
Path
examples/rest-api/cache-redis

Overview

Helix Spring Boot webservice that shows how to cache application data in Redis with helix-cache-redis.

Run this example from the shared examples build:

Run

Run this example from the shared examples build


./gradlew -p examples runExample -Pexample=rest-api/cache-redis --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • the Helix API starter baseline
  • configuring a JedisPool and RedisCacheService bean in a Spring Boot service
  • using JacksonRedisCacheValueSerializer to store JSON cache values in Redis
  • reading from a backing catalog source on a cache miss and serving Redis on a cache hit
  • key prefixes and TTL settings that keep cache keys organized
  • evicting a cached entry so the next request repopulates Redis from the backing source

Endpoints

  • GET /v1/cache-redis/configuration
  • GET /v1/cache-redis/products/{productId}
  • DELETE /v1/cache-redis/products/{productId}
  • GET /liveness
  • GET /health

Example success response

{
  "request_id": "generated-by-helix",
  "status": "SUCCESS",
  "timestamp": "2026-03-15T12:34:56+0000",
  "data": {
    "productId": "sku-123",
    "name": "Helix Hoodie",
    "priceInCents": 6500,
    "currency": "USD",
    "catalogVersion": "catalog-v1",
    "backendLoadCount": 1,
    "cacheHit": false,
    "cacheName": "product-pricing-cache",
    "keyPrefix": "cache-redis-example",
    "ttlSeconds": 120,
    "source": "catalog-source"
  }
}

Development

Building the Application

Run the following command to build the service:

Command

Building the Application


./gradlew clean build

Testing the Application

Run the following command to run the service tests:

Command

Testing the Application


./gradlew test
./gradlew integration

Trying the API

Run a local Redis instance on localhost:6379, then start the service:

Then try:

The first product lookup is a cache miss, so the service loads the product from the backing catalog and stores it in Redis. The second lookup is a cache hit served directly from Redis. After the DELETE, the next lookup repopulates the cache and returns a new catalog version so you can see the reload happen.

Command

Trying the API


./gradlew bootRun

Command

Trying the API


curl http://localhost:8080/v1/cache-redis/configuration

curl http://localhost:8080/v1/cache-redis/products/sku-123

curl http://localhost:8080/v1/cache-redis/products/sku-123

curl -X DELETE http://localhost:8080/v1/cache-redis/products/sku-123

curl http://localhost:8080/v1/cache-redis/products/sku-123