简体   繁体   中英

Strategy to manage Redis collections in Java

I have a web application where I use a relational database and Redis for storing my key/value pairs. I am using Spring Data Redis in my DAO methods to access Redis collections. The problem is that having many Redis collections in the application makes it really difficult to manage them. I believe that each collection should be accessed from one single place only ie writes and reads for one collection should be centralized, but that is not the case in my app currently. So I would like to come up with a proper and encapsulated access mechanism for all my Redis collections.

How should I structure my app to accomplish this?

Have a look at org.springframework.data.redis.core.RedisTemplate class. a generic template to access all redis provided data structure

Create classes which deals with only one entity at a time. For example, if you have domain objects Users and Posts (for a Twitter clone example), you can create UserRepository and PostRepository each dealing with their own entities.
UserRepository deals with adding users, deleting users, updating user details and so on. And PostRepository does so for posts. You can use these repositories in service classes to achieve business functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM