Spring RedisTemplate : Serialise multiple Model classes into JSON.Need to use Multiple RedisTemplates?

后端 未结 3 1226
野性不改
野性不改 2020-12-29 05:38

I am using Spring Redis support to save my objects in Redis.

I have several DAOs which handle different Model classes:

For example, ShopperHistoryDao

3条回答
  •  别那么骄傲
    2020-12-29 06:01

    Yes, the RedisTemplate seems to be designed to have a single instance of the value serializer.

    I was going to suggest the possible workaround of having a RedisSerializer which contains a Map of inner serializers so you can use one RedisTemplate with a serializer that can handle multiple types - but since RedisSerializer does not offer methods like boolean canDeserialize(..) (as the HTTP MessageConverters in Spring MVC have) this doesn't seem possible.

    So it seems that you are stuck with having multiple RedisTemplate instances.

提交回复
热议问题