Redis / Data

Redis integration for Spring Boot microservices

Spring Middleware provides a Redis module for Spring Boot microservices with low-level connection management and higher-level primitives for typed key-value operations, distributed locks, and mutex-based coordination. The goal is to keep Redis integration reusable and explicit without turning it into scattered ad hoc infrastructure code.

Typed key-value operations Distributed locks Redis mutexes Connection pooling Cluster-aware configuration Spring Boot Redis integration

What the Redis module provides

The Redis module is not limited to raw connection wiring. It provides a small platform model around Redis access: connection parameters, typed service APIs, and coordination utilities for distributed execution.

  • Redis connection and pool configuration
  • Typed key-value operations through RedisService
  • Distributed locks and mutex utilities
  • Reusable Redis patterns across services

Key runtime concepts

  • RedisConnectionParameters: Spring configuration model for host, port, timeout, pool, and cluster options.
  • RedisService: typed service API for key-value reads, writes, and deletes.
  • RedisLock / RedisLockFactory / RedisMutex: coordination primitives for distributed workflows.

High-level Redis view

Services interact with Redis through a typed service abstraction, while connection settings and coordination primitives remain explicit and configurable.

Application Service Spring Middleware Redis Module typed operations • locks connection management Redis

Configuration

The module reads Redis settings from the redis prefix. This includes connection parameters, pool sizing, timeouts, and cluster-related options.

Minimal Redis configuration

redis:
  host: ${REDIS_HOST:localhost}
  port: ${REDIS_PORT:6379}
  database: 0
  timeout: 2000
  max-pool-conn: 10
  max-idle-pool-conn: 10
  min-idle-pool-conn: 1
  max-wait-millis: 1000
  is-cluster: false

What is configured here

  • Redis host and port
  • Database selection
  • Connection timeout
  • Pool size and idle thresholds
  • Cluster mode toggle

Typed key-value operations

The Redis module promotes typed access patterns instead of scattering raw string keys and unstructured payload handling across services.

Domain contracts

Services define Redis-facing domain types by implementing RedisKey, RedisValue, and RedisKeyValue.

  • Typed keys
  • Typed values
  • Typed key-value pairs

RedisService

RedisService provides a generic API for reading, writing, and deleting typed key-value pairs with custom functional converters.

Conceptual usage

- Autowire RedisService<MyKey, MyValue, MyKeyValue>
- Build a collection of keys
- Retrieve typed key/value pairs
- Apply domain-specific converters

Why this matters

  • Consistency: Redis access follows the same typed model across services.
  • Reuse: converters and access patterns can be shared.
  • Clarity: Redis usage stays close to the domain model.

Distributed locks and coordination

The module also provides explicit coordination primitives for distributed execution, useful when multiple nodes can update the same shared resource.

RedisLock

Represents a distributed lock used to protect multi-step operations that should not run concurrently across nodes.

RedisLockFactory

Creates lock instances so services can acquire distributed coordination when needed.

RedisMutex

Provides mutex-style coordination for cases where strong cross-node synchronization is required.

Service Node A Redis Lock coordination point Service Node B

Notes and best practices

Redis is fast, but good usage still depends on key design, payload discipline, and coordination boundaries.

Tune pool settings

Adjust connection pool configuration to match traffic patterns and deployment size.

Keep keys focused

Prefer small, well-scoped keys and compact payloads to keep Redis usage efficient.

Lock only when needed

Use distributed locks for real coordination boundaries, not as a default for every operation.

Where to look in the code

The Redis module is built around a small set of core configuration and service classes.

RedisConnectionParameters

redis core

.../redis/config/RedisConnectionParameters.java

RedisServiceImpl

redis core

.../redis/service/RedisServiceImpl.java

RedisLockFactory

redis core

.../redis/service/RedisLockFactory.java