feat: Add Redis cache adapter#222
Open
vazarkevych wants to merge 3 commits into
Open
Conversation
added 3 commits
July 3, 2026 16:26
Adds an optional growthbook-cache-redis Gradle module providing Redis-backed GbCacheManager implementations: - AbstractRedisGbCacheManager with shared key-prefixing, TTL and last-updated timestamp handling. - JedisGbCacheManager (Jedis pool) and LettuceGbCacheManager (Lettuce connection) adapters; both clients are compileOnly so consumers add only the one they use. - Unit tests with mocked clients plus opt-in Testcontainers integration tests (separate integrationTest task, requires Docker).
- getLastUpdatedMillis now reads only the updatedAt hash field (HGET) instead of fetching the whole payload with HGETALL, so freshness checks no longer transfer the full feature JSON. - Document that Redis Cluster is not supported (multi-key DEL fails with CROSSSLOT, SCAN covers a single node) and suggest a hash-tag key prefix as a workaround. - GBFeaturesRepository.shutdown() no longer clears the cache store: persisted features are meant to survive restarts, and with shared stores (e.g. Redis) clearing on shutdown would wipe the cache for every other SDK instance sharing the namespace. - Fix stale POM description (adapter supports both Jedis and Lettuce).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Redis cache adapter (growthbook-cache-redis)
Summary
Adds a new optional Gradle module,
growthbook-cache-redis, that provides a Redis-backed implementation of the SDK'sGbCacheManager. This enables sharing the GrowthBook feature cache across multiple instances/pods instead of keeping it in-process or on the local filesystem.Two Redis clients are supported out of the box:
JedisGbCacheManagerLettuceGbCacheManagerBoth client dependencies are
compileOnly, so consumers include only the client they actually use; nothing is forced onto the SDK's runtime classpath.Design
Shared base, thin adapters
AbstractRedisGbCacheManagercontains the shared logic:FeatureCacheExceptionwrappingEach adapter only implements low-level Redis operations:
writeHashreadHashdeleteByPrefixStorage format
Each cache entry is stored as a Redis hash with:
dataupdatedAt(epoch millis)RedisCacheEntrycentralizes field names and mapping so both adapters use the same on-the-wire format.getLastUpdatedMillis()is backed byupdatedAt, enabling freshness-based cache refresh skipping in the SDK.Configuration (self-typed builder)
AbstractRedisCacheOptionsprovides configuration:keyPrefix
Namespace for all keys (default:
growthbook:features:).clearCache()removes only keys under this prefix viaSCAN+DEL(no blockingKEYS).ttl
Optional per-entry TTL applied on write.
nullmeans no expiration.clock
Injectable clock for deterministic testing.
Connection ownership
The caller owns the lifecycle of:
JedisPoolStatefulRedisConnectionThe adapter only borrows connections and executes commands.
Error handling
null)FeatureCacheExceptionwith the affected key for contextUsage
Jedis
Lettuce
Testing
Unit tests
Integration tests
integrationTestsource setintegrationTestGradle taskcheck, so standard builds do not require DockerBuild / packaging
settings.gradlesourceCompatibility/targetCompatibility = 1.8)libmodule