spring-projects / spring-projects/spring-data-redis

@EnableRedisRepositories cannot be configured to use their own RedisTemplate beans

Open
#1,946 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

for: team-attention status: pending-design-work theme: 4.0
Dominant language
Java
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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 ???

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with @EnableRedisRepositories and the repository configuration path that selects the container factory, then compare it with the reported redisTemplateRef and the existing RedisTemplate usage. The change is complete when separate repository configurations can select distinct Redis containers and repository.save updates the intended East and West regions independently.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.