Exposed R2DBC Redisson Cache
Latest stable Based on Exposed release 1.11.0
This adapter combines coroutine-first R2DBC with Redis through Redisson async maps. It implements the common cache repository contract without hiding lifecycle or durability choices.
Problem
Section titled “Problem”Cache and database state can diverge when a miss, write, invalidation, timeout, cancellation, or shutdown completes only partly. The adapter supplies the integration; the application still defines acceptable staleness and failure behavior.
When to use it
Section titled “When to use it”Use this module when Redis through Redisson async maps is the chosen backend and the persistence path is coroutine-first R2DBC. Compare all six adapters in the cache selection guide before adding infrastructure.
Coordinates
Section titled “Coordinates”dependencies { implementation(platform("io.github.bluetape4k:bluetape4k-dependencies:<version>")) implementation("io.github.bluetape4k.exposed:bluetape4k-exposed-r2dbc-redisson")}Users select the central BOM version; this page records the stable 1.11 source line.
Core concepts
Section titled “Core concepts”get and getAll are read-through operations. Cache-aside is an application-owned DB update followed by invalidation. True write-through requires the configured writer to finish DB persistence before returning. Write-behind accepts a delayed durability window. Ordinary put must not be called write-through without that writer policy. This adapter is the local cached map’s sync strategy, size, TTL, and idle time bound local divergence.
Quick start
Section titled “Quick start”Extend AbstractR2dbcRedissonRepository and provide table, extractId, ResultRow.toEntity, and the update/insert DSL hooks. Construct it with a reviewed RedissonCacheConfig.
repository.use { repo -> val current = repo.get(id) // miss -> DB loader -> cache current?.let { repo.put(id, it) } // durability follows write mode repo.invalidate(id) // cache-only by default}API by task
Section titled “API by task”| Task | API |
|---|---|
| Cache-backed read | containsKey, get, getAll |
| DB bypass | findByIdFromDb, findAllFromDb, countFromDb |
| Policy-controlled write | put, putAll |
| Eviction | invalidate, invalidateAll, clear |
| Entity mapping | ResultRow.toEntity, extractId, update/insert hooks |
| Lifecycle | close |
Recommended patterns
Section titled “Recommended patterns”Keep one repository per cache namespace and close it with the application. For cache-aside, commit the DB transaction before invalidating. Treat write-through failure as an incomplete write. Before write-behind, expose queue/dead-letter state and define the shutdown drain budget. Keep key prefixes and serialized value formats stable.
Integrations
Section titled “Integrations”The module joins Exposed R2DBC, the shared cache foundation, and Redis through Redisson async maps. Loader/writer adapters own the cache-to-table bridge; the application owns the surrounding service transaction and client lifecycle.
Configuration
Section titled “Configuration”RedissonCacheConfig controls namespace, TTL/expiry, cache/write mode, and backend limits. Unsafe binary codec families are rejected unless trustedBinaryCache=true. Validate positive durations and bounded batch/queue sizes at startup.
Failure modes
Section titled “Failure modes”Invalidation is cache-only unless deleteFromDBOnInvalidate=true; write-behind and cancellation never make cache plus DB atomic. A cache hit can be stale, a backend success can be followed by DB failure, and DB commit can be followed by failed invalidation. Record these as distinct states.
Operations
Section titled “Operations”The application owns RedissonClient; repository calls await Redisson futures and R2DBC loader/writer transactions. Monitor hit/miss, backend latency, retries/timeouts, queue depth, rejected or dead-letter writes, invalidation lag, and shutdown drain. Set separate SLOs for cache and database paths.
Testing
Section titled “Testing”Use isolated cache and database fixtures with unique namespaces. Prove miss loading, partial getAll misses, each enabled write mode, cache-only invalidation, TTL, partial failure, and lifecycle cleanup.
./gradlew :bluetape4k-exposed-r2dbc-redisson:testWorkshops and learning path
Section titled “Workshops and learning path”- Read Exposed cache foundation.
- Choose a backend in cache selection.
- Implement read-through plus cache-only invalidation first.
- Add partial-failure and shutdown tests before near cache or write-behind.
- Continue with exposed-workshop.
Limitations
Section titled “Limitations”The adapter does not create a distributed transaction, provision the backend, migrate stored cache values, or decide whether stale data is safe. It is the local cached map’s sync strategy, size, TTL, and idle time bound local divergence.
Release diagrams
Section titled “Release diagrams”These diagrams are loaded directly from README assets published with the 1.11.0 release and pinned to its immutable commit. They describe this manual’s released structure and runtime flows, not later Snapshot changes. Select a preview to open the SVG at the same release commit.
R2DBC Redisson coroutine cache architecture diagram
Section titled “R2DBC Redisson coroutine cache architecture diagram”Release README: exposed/r2dbc-redisson/README.md
R2DBC Redisson repository hierarchy diagram
Section titled “R2DBC Redisson repository hierarchy diagram”Release README: exposed/r2dbc-redisson/README.md
R2DBC Redisson read-through sequence diagram
Section titled “R2DBC Redisson read-through sequence diagram”Release README: exposed/r2dbc-redisson/README.md
R2DBC Redisson write-through sequence diagram
Section titled “R2DBC Redisson write-through sequence diagram”Release README: exposed/r2dbc-redisson/README.md
R2DBC Redisson write-behind sequence diagram
Section titled “R2DBC Redisson write-behind sequence diagram”Release README: exposed/r2dbc-redisson/README.md




