Skip to content

Can RedisTemplate support MessagePack serialization? #518

Open
@lyhu

Description

@lyhu

In the AI embedding scenario, it is expected to set messages in MsgPack format to reduce server memory usage. Therefore, it is considered to replace the existing RedisTemplate creation in the following way. Is this feasible?

  @Bean(name = "redisOmTemplate")
  @Primary
  public RedisTemplate<?, ?> redisTemplate(JedisConnectionFactory connectionFactory) {
    RedisTemplate<?, ?> template = new RedisTemplate<>();
    template.setKeySerializer(new StringRedisSerializer());
    template.setDefaultSerializer(new StringRedisSerializer());
    template.setConnectionFactory(connectionFactory);

    return template;
  }

=>

  @Bean(name = "redisOmTemplate")
  @Primary
  public RedisTemplate<?, ?> redisTemplate(JedisConnectionFactory connectionFactory) {
      RedisTemplate<?, ?> template = new RedisTemplate<>();
      template.setConnectionFactory(connectionFactory); 

      ObjectMapper objectMapper = new ObjectMapper(new MessagePackFactory());

      Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(objectMapper, Object.class);
      template.setValueSerializer(serializer);
      template.setHashValueSerializer(serializer);
      return template; 
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions