Skip to content
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

@EnableRedisRepositories cannot be configured to use their own RedisTemplate beans #1946

Open
aem-quotient opened this issue Jan 19, 2021 · 7 comments
Labels
for: team-attention An issue we need to discuss as a team to make progress status: pending-design-work Needs design work before any code can be developed theme: 4.0

Comments

@aem-quotient
Copy link

aem-quotient commented Jan 19, 2021

I have a use case like using two different regions Redis. Since the Redis is not synced between two different data centers. Need to update the data center in a synchronized fashion.

I'm facing a problem while updating the cache, The cache is updated in only one region.

@EnableRedisRepositories(basePackageClasses = {RefreshEastCacheRepository.class}, redisTemplateRef = "refreshEastRedisTemplate")
@EnableRedisRepositories(basePackageClasses = {RefreshWestCacheRepository.class}, redisTemplateRef = "refreshWestRedisTemplate")

I have configured the two different Redis in the same project and in one of the configurations I have added @primary(East Region) for the base use-case.

@repository("eastRepository")
public interface RefreshEastCacheRepository<T, D> extends CrudRepository<T, D>, QueryByExampleExecutor {
}
@repository("westRepository")
public interface RefreshWestCacheRepository<T, D> extends CrudRepository<T, D>, QueryByExampleExecutor {
}

I have Autowired the above repository in my class. When there is any update happened, the cache is updated only in the east region. but it's not updating in the west. If we use RedisTemplate we can update in the two different regions. But I feel comfortable using the repository.save method to update in the cache.

When I dig deeper into the code the container factory is the default for all the Repository and it's the same for all the Repositories.

I need a way to differentiate the two different containers at the Repository level. In the @EnableJPARepository, it allows us to add the EntityBeanFactory but in the EnableRedisRepositories we don't have an option to point out the right container factory.

Is there any better way to do that ???

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 19, 2021
@mp911de
Copy link
Member

mp911de commented Jan 19, 2021

Note that @Repository has no effect on Spring Data repositories as @Repository is a component annotation to be used with Java classes, not interfaces.

The issue is caused by RedisRepositoryConfigurationExtension that configures several beans with the same name and backs off if there is already a bean registered with a particular name. In this case, RedisKeyValueAdapter is configured with the first RedisTemplate and reused for both repositories.

For now, there's no simple workaround. You need to spin up your repositories via RedisRepositoryFactory and wire all beans (RedisKeyValueTemplate, RedisKeyValueAdapter, RedisMappingContext) yourself to create an isolated repository per Template.

I'm going to take this issue to the team for further discussion.

@mp911de mp911de added the for: team-attention An issue we need to discuss as a team to make progress label Jan 19, 2021
@mp911de
Copy link
Member

mp911de commented Jan 19, 2021

One more thing: RedisReactiveAutoConfiguration is part of Spring Boot. Can you file there a ticket that RedisReactiveAutoConfiguration should be only activated if there's a single ReactiveRedisConnectionFactory bean?

@mp911de mp911de changed the title Redis Reactive is not working for multiple datasource @EnableRedisRepositories cannot be configured to use their own RedisTemplate beans Jan 19, 2021
@aem-quotient
Copy link
Author

Sure I will the ticket there as well

@aem-quotient
Copy link
Author

@mp911de Any update on this ??

@aem-quotient
Copy link
Author

Tried the above approach which was suggested by you. But no luck.

@mp911de mp911de added the status: pending-design-work Needs design work before any code can be developed label Jan 20, 2021
@mp911de mp911de added this to the 3.x milestone Jan 20, 2021
@schauder schauder removed the status: waiting-for-triage An issue we've not yet triaged label Feb 8, 2021
@mp911de
Copy link
Member

mp911de commented Mar 18, 2021

Related to spring-projects/spring-data-keyvalue#363

@sureshkmit
Copy link

This feature will be very useful. Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention An issue we need to discuss as a team to make progress status: pending-design-work Needs design work before any code can be developed theme: 4.0
Projects
None yet
Development

No branches or pull requests

5 participants