spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Support redis specific repository.

Open junghoon-vans opened this issue 1 year ago • 3 comments

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.

junghoon-vans avatar Dec 28 '23 01:12 junghoon-vans

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.

mp911de avatar Dec 28 '23 09:12 mp911de

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.

junghoon-vans avatar Dec 29 '23 00:12 junghoon-vans

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.

mp911de avatar Dec 29 '23 08:12 mp911de