Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can RedisTemplate support MessagePack serialization? #518

Open
lyhu opened this issue Oct 20, 2024 · 0 comments
Open

Can RedisTemplate support MessagePack serialization? #518

lyhu opened this issue Oct 20, 2024 · 0 comments

Comments

@lyhu
Copy link

lyhu commented Oct 20, 2024

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; 
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant