Skip to content

Improve cache auto-configuration for Redis #10944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2017

Conversation

ryonday
Copy link

@ryonday ryonday commented Nov 6, 2017

Expose key prefix, TTL and null value settings for spring-data-redis' RedisCacheConfiguration in Spring .properties/yml configuration files.

Example:

spring.cache.redis.ttl=PT15M
spring.cache.redis.keyPrefix=foo
spring.cache.redis.useKeyPrefix=false
spring.cache.redis.cacheNullValues=false

Fixes gs-10795

Expose key prefix, TTL and null value settings for spring-data-redis'
RedisCacheConfiguration in Spring .properties/yml configuration files.

Example:

spring.cache.redis.ttl=PT15M
spring.cache.redis.keyPrefix=foo
spring.cache.redis.useKeyPrefix=false
spring.cache.redis.cacheNullValues=false

Fixes gs-10795
@ryonday
Copy link
Author

ryonday commented Nov 6, 2017

Addresses this

@snicoll snicoll changed the title Improve spring-boot-autoconfigure for Redis caches Improve cache auto-configuration for Redis Nov 7, 2017
Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thank you so much for your first contribution to Spring Boot. I've made a few suggestions, can you please have a look to them?

You can squash and push force on your existing branch or just push an additional commit with your changes.

public static class Redis {

/**
* The TTL for entries. By default, entries do not expire, a value of zero
Copy link
Member

Choose a reason for hiding this comment

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

Configuration key descriptions do not start with The, A, etc. Please look at existing keys for inspiration

* The TTL for entries. By default, entries do not expire, a value of zero
* indicates an eternal entry, and the given value will be converted to seconds..
*
* @see Duration#parse(CharSequence)
Copy link
Member

Choose a reason for hiding this comment

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

We don't make such @see link here. We use the javadoc to infer the description. Can you please remove them all?

private boolean cacheNullValues = true;

/**
* The non-null Redis key prefix to use instead of the default one.
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure what you mean by "non-null" here.

return this;
}

public Optional<String> getKeyPrefix() {
Copy link
Member

Choose a reason for hiding this comment

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

Configuration properties must be JavaBean properties (the type must match) and we don't support Optional here.

@@ -57,13 +59,38 @@

@Bean
public RedisCacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {

Copy link
Member

Choose a reason for hiding this comment

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

Please refrain from making unnecessary formatting changes.

RedisCacheManagerBuilder builder = RedisCacheManager
.builder(redisConnectionFactory);
.builder(redisConnectionFactory).cacheDefaults(getConfiguration());

Copy link
Member

Choose a reason for hiding this comment

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

Idem

List<String> cacheNames = this.cacheProperties.getCacheNames();
if (!cacheNames.isEmpty()) {
builder.initialCacheNames(new LinkedHashSet<>(cacheNames));
}

Copy link
Member

Choose a reason for hiding this comment

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

Idem

@snicoll snicoll added priority: low status: waiting-for-feedback We need additional information before we can continue type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 7, 2017
* Remove unnecessary formatting changes
* Discontinue use of Optional for Redis property configuration
* Remove @see tags
* Change verbiage for property descriptions

Fixes gs-10795
@ryonday
Copy link
Author

ryonday commented Nov 7, 2017

Thanks so much for the detailed feedback, @snicoll; I hope that the follow-up commit has addressed your concerns!

I'm happy to be able to give back in some small way to a project that I've used so much throughout my career.

@snicoll snicoll self-assigned this Nov 8, 2017
@snicoll snicoll removed the status: waiting-for-feedback We need additional information before we can continue label Nov 8, 2017
@snicoll snicoll added this to the 2.0.0.M7 milestone Nov 10, 2017
@snicoll snicoll merged commit 1ba6469 into spring-projects:master Nov 10, 2017
snicoll added a commit that referenced this pull request Nov 10, 2017
snicoll added a commit that referenced this pull request Nov 10, 2017
* pr/10944:
  Polish "Improve cache auto-configuration for Redis"
  Improve cache auto-configuration for Redis
  Respond to MR feedback
  Improve spring-boot-autoconfigure for Redis caches
@snicoll
Copy link
Member

snicoll commented Nov 10, 2017

@ryonday Thanks for the feedback. They did partially and I had an extra polish pass. It's now merged in master.

@ryonday
Copy link
Author

ryonday commented Nov 10, 2017

Thanks so much for the polish pass, I have a few more small PR ideas and it helps to have a template for the preferred conventions and style to make it easier on reviewers!

Cheers!

@ryonday ryonday deleted the redis-cache-config branch November 10, 2017 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants