Skip to content

Include the default application in the Redis backend - #3282

Merged
ryanjbaxter merged 2 commits into
spring-cloud:5.0.xfrom
HDPark95:fix/gh-3134-redis-default-application
Sep 3, 2026
Merged

Include the default application in the Redis backend#3282
ryanjbaxter merged 2 commits into
spring-cloud:5.0.xfrom
HDPark95:fix/gh-3134-redis-default-application

Conversation

@HDPark95

@HDPark95 HDPark95 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

RedisEnvironmentRepository only reads the hashes named after the requested application (app, app-<profile>), so properties under the shared application key are never returned. The other backends include them: jdbc, mongodb, credhub, native and aws-s3.

This adds the default application keys, ordered the way jdbc and credhub do, so the requested application still wins over the shared defaults: app-p2, application-p2, app-p1, application-p1, app, application. When the requested application is application the key list is unchanged.

New test in RedisEnvironmentRepositoryIntegrationTests: on 5.0.x it fails with ["redis:myapp-prod", "redis:myapp"] and passes with the change.

Fixes gh-3134

@ryanjbaxter ryanjbaxter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you submit this against the 5.0.x branch?

private List<String> addKeys(String application, List<String> profiles) {
List<String> keys = new ArrayList<>();
keys.add(application);
List<String> applications = new ArrayList<>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure application can be null and can be comma delimated, both of which are not handled here

private List<String> normalize(String commaDelimitedItems, String defaultItem) {
return normalize(defaultItem + "," + commaDelimitedItems);
}
/**
* Splits the comma-delimited items and returns the reversed distinct items.
*/
private List<String> normalize(String commaDelimitedItems) {
var items = Arrays.stream(split(commaDelimitedItems))
.distinct()
.filter(StringUtils::hasText)
.collect(Collectors.toList());
Collections.reverse(items);
return items;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in 1411856, following CredhubEnvironmentRepository#normalize: application goes through commaDelimitedListToStringArray, trimmed, filtered on hasText and de-duplicated, with application prepended. So null resolves to the shared hash only, and app1,app2 reads every listed hash with later names taking precedence, the same order the Credhub backend produces. Two integration tests cover both cases (null -> [application-prod, application]; "app1, app2,app1" -> [app2-prod, app1-prod, application-prod, app2, app1, application]). Reverting the source change fails both.

@HDPark95
HDPark95 force-pushed the fix/gh-3134-redis-default-application branch from f5d4c2a to 073e4fe Compare September 3, 2026 00:36
@HDPark95
HDPark95 changed the base branch from main to 5.0.x September 3, 2026 00:37
RedisEnvironmentRepository only read the hashes named after the requested
application, so properties stored under the shared "application" key were
never returned. The other backends include them: JdbcEnvironmentRepository,
MongoDbEnvironmentRepository, CredhubEnvironmentRepository,
NativeEnvironmentRepository and AwsS3EnvironmentRepository.

Add the default application keys and order them the way jdbc and credhub do,
so the requested application still takes precedence over the shared defaults.
When the requested application is "application" the key list is unchanged.

Fixes spring-cloudgh-3134

Signed-off-by: HDPark95 <qkrgusen456@gmail.com>
@HDPark95
HDPark95 force-pushed the fix/gh-3134-redis-default-application branch from 073e4fe to 7967ffc Compare September 3, 2026 00:42
@HDPark95

HDPark95 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@ryanjbaxter the PR is targeting 5.0.x already (base branch 5.0.x, one commit on top). Let me know if you'd rather have it against a different branch. The null / comma-delimited handling is in 1411856, see the inline reply.

Mirrors CredhubEnvironmentRepository#normalize: a null application resolves to
the shared `application` hash only, and a comma-delimited list such as
`app1,app2` reads every listed hash with later names taking precedence, the
same order the other backends use.

Signed-off-by: HDPark95 <qkrgusen456@gmail.com>
@HDPark95
HDPark95 force-pushed the fix/gh-3134-redis-default-application branch from 1411856 to 2106eed Compare September 3, 2026 02:54
@ryanjbaxter
ryanjbaxter merged commit a967116 into spring-cloud:5.0.x Sep 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redis Environment repository not respecting/returning default "application" values

3 participants