spring-data-redis
spring-data-redis copied to clipboard
Support redis specific repository.
Previously, we were only specifying KeyValueRepository
as the IdentifyingTypes of the repository.
This can be problematic when used with another implementation of KeyValueRepository,
so we need to provide a Redis-specific repository interface.
For example, if you have an implementation of a KeyValue named AnotherKV
, as shown below,
Spring Data will not be able to determine which datastore it should run to.
interface MyRedisRepository extends KeyValueRepository<User, Long> { }
interface MyAnotherKVRepository extends KeyValueRepository<User, Long> { }
If Redis-specific repositories were added, this confusion could be eliminated.
interface MyRedisRepository extends RedisRepository<User, Long> { } // This always works with Redis.
By providing a module-specific repository, we can ensure that the repository is bound to a redis.
This is by design to avoid having another empty store-specific interface.
Repository disambiguation works also through annotations on the domain type. If you add @RedisHash
to your entity, you can leverage disambiguation.
Let me know how this goes.
Of course, as you say, there is a way to use annotations, but according to the reference documentation, a module-based repository should also be provided.
However, in the current implementation, there is no repository interface that is specific to Redis, so there are limited ways to utilize a module-based repository.
So I created a mark interface that is simply an extension of KeyValueRepository. This interface is only utilized by Redis, so it is clearly distinguishable from other repositories.
Over time, we've realized that introducing module-specific interface types are a harm to the desired programming model. Again, introducing empty marker interfaces do not improve such arrangements but they introduce technology-specific dependencies whereas Spring Data aims to create a store-independent experience in which calling code shouldn't be aware of the technology-specifics.