fix: Enable configuration for Redis usage#141
Merged
pallakartheekreddy merged 3 commits intoMar 25, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a configuration flag to enable/disable Redis usage and gates Redis-dependent code paths (RedisStoreUtil, DIAL max-index allocation, and health checks) based on that flag.
Changes:
- Introduced
redis.cache.enabledconfiguration flag (defaulted tofalseinapplication.conf). - Updated Redis utilities/factory to short-circuit or throw when Redis is disabled.
- Conditioned Redis and DIAL max-index health checks on Redis being enabled.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| conf/application.conf | Adds redis.cache.enabled flag to control Redis usage. |
| app/commons/JedisFactory.java | Initializes Redis pool only when enabled; adds isEnabled(); guards connection/return methods. |
| app/utils/RedisStoreUtil.java | Skips Redis reads/writes when Redis is disabled. |
| app/utils/DialCodeGenerator.java | Falls back to Cassandra-based index increment when Redis is disabled. |
| app/managers/IHealthCheckManager.java | Treats Redis as healthy when Redis is disabled. |
| app/managers/HealthCheckManager.java | Skips Redis-related checks (and DIAL max index check) when Redis is disabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f7f5c0f to
1425713
Compare
|
pallakartheekreddy
approved these changes
Mar 25, 2026
fd1a5da
into
Sunbird-Knowlg:develop
2 of 4 checks passed
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.



Summary
This PR makes Redis fully optional for the DIAL code service. When
redis.cache.enabled=false(the new default), the service operates entirely on Cassandra with no dependency on a running Redis instance, while preserving correctness and concurrency safety.Problem
Previously Redis was a hard runtime requirement for DIAL code generation. The
dialcode_max_indexcounter lived primarily in Redis, and the service would throw an error if Redis was unavailable or its counter had drifted behind Cassandra. There was no supported path to run the service without Redis.Changes
app/commons/JedisFactory.javaredis.cache.enabledconfig flag (defaultfalse) at startup.true.isEnabled()is the single gate used by all other classes — no other code touches Redis directly without checking this first.app/utils/RedisStoreUtil.javaJedisFactory.isEnabled()and return safely (null/ no-op) when Redis is disabled, removing any risk of NPE if called when Redis is off.app/dbstore/SystemConfigStore.java— new methodgetAndIncrementDialCodeIndex()dialcode_max_index.UPDATE … SET prop_value = N+1 WHERE prop_key = 'dialcode_max_index' IF prop_value = Nexecuted directly viaCassandraConnector.getSession()(not the inheritedPreparedStatementhelper, which cannot return the[applied]column).INCRBYas the atomic counter when Redis is disabled, making Cassandra the single authoritative counter.app/utils/DialCodeGenerator.javagetMaxIndex(): when Redis is disabled, delegates each index allocation togetAndIncrementDialCodeIndex()(CAS-based) instead of RedisINCRBY.generate(): guards the finalsetMaxIndex()(the Redis→Cassandra sync write) behindJedisFactory.isEnabled().When Redis is disabled this write is intentionally skipped — Cassandra already holds the committed index from the CAS loop, and a plain write at the end would race with concurrent requests and could overwrite a higher index.
app/managers/HealthCheckManager.java&IHealthCheckManager.javaJedisFactory.isEnabled()./healthresponse — onlyelasticsearchandcassandra dbare reported.IHealthCheckManager.checkRedisHealth()returnstrueimmediately when Redis is disabled (no false-positive failures).conf/application.confredis.cache.enabled=falseas the explicit default, making the no-Redis path the safe out-of-the-box configuration.test/resources/application.confredis.cache.enabled=falseexplicitly so test intent is self-documenting and tests are protected from future default changes.test/manager/DialCodeManagerImplTest.javagenerateDialCodesProduceUniqueIndicesWhenRedisDisabledTest: generates two sequential batches of 3 DIAL codes each and asserts no code appears in both batches, proving the CAS allocator never re-uses an index.import static org.junit.Assert.assertFalse(compilation error).test/manager/HealthCheckManagerTest.javagetAllServicesHealthWithRedisDisabledTest: asserts thatelasticsearchandcassandra dbchecks are present, and thatredis cacheandDIAL Max Indexchecks are absent when Redis is disabled.build/build.sh--platform linux/amd64to the Docker build command to produce the correct image architecture when building on Apple Silicon machines.How index allocation works — before vs after
INCRBYIF prop_value = N)setMaxIndex()after generateTest plan
sbt test(ormvn test) passes withredis.cache.enabled=false.generateDialCodesProduceUniqueIndicesWhenRedisDisabledTestpasses — no index reuse across sequential generation requests.getAllServicesHealthWithRedisDisabledTestpasses — only ES and Cassandra checks appear in/health.getAllServicesHealthTest,checkCassandraHealth,checkElasticSearchHealth,checkRedisHealthall continue to pass.redis.cache.enabled=falseand no Redis running —POST /v1/dialcode/generatesucceeds and returns unique codes.redis.cache.enabled=trueand Redis running — existing Redis-backed flow is unchanged.🤖 Generated with Claude Code