0

I'm interacting with Redis in my spring boot application and find it interesting w.r.t. how spring-data-redis serializes objects. Basically you have a RedisTemplate<K, V> with key/value serializer pairs according to K, V. When it comes to Hash, you add another pair of serializers. So far so good until the other day I saw a Redis Stream example which uses a ReactiveRedisTemplate<String, String> for serializing ObjectRecord<K', V'> - if a string serializer could serialize/deserialize ObjectRecord entries (hash), it could serialize/deserialize anything. So why don't the community expose it as another standard/generic spring-data-redis serializer? for as I could see, it prints quite pretty representation of objects along with type metadata for the generic/Object fields, better than GenericJackson2JsonRedisSerializer in being not a 3rd party dependency.

For example the following serialized object is from a stream:

XREAD COUNT 2 STREAMS foo-global-event-stream 0-1
1) 1) "foo-global-event-stream"
   2) 1) 1) "1683788669753-0"
         2) 1) "_class"
            2) "com.foo.sdk.redis.entity.Event"
            3) "data._class"
            4) "com.foo.sdk.redis.entity.Point"
            5) "data.x"
            6) "1"
            7) "data.y"
            8) "2"
            9) "id"
            10) "789"
            11) "source.threadName"
            12) "restartedMain"
            13) "source.user._class"
            14) "com.foo.sdk.redis.entity.User"
            15) "source.user.id"
            16) "100"
            17) "source.user.name"
            18) "Phi"

Am I missing something? just confused, it seems only objects in Streams can be serialized/deserialized with string serializer, others e.g. Hash gives CCE.

See also:

https://github.com/spring-projects/spring-data-redis/issues/2391

How to configure Spring Redis Configuration to use Hash instead of string serialization

Will Phi
  • 101
  • 3

0 Answers0