content: package ljl.bilibili.notice.config;
  
  
  import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.redis.connection.RedisConnectionFactory;
  import org.springframework.data.redis.core.RedisTemplate;
  import org.springframework.data.redis.listener.RedisMessageListenerContainer;
  import org.springframework.data.redis.serializer.RedisSerializer;
  import org.springframework.data.redis.serializer.StringRedisSerializer;
  
  @Configuration
  public class RedisConfig {
  
      private final RedisConnectionFactory redisConnectionFactory;
  
      public RedisConfig(RedisConnectionFactory redisConnectionFactory) {
          this.redisConnectionFactory = redisConnectionFactory;
      }
  
      @Bean
      public <T> RedisTemplate<String, T> objectRedisTemplate(RedisConnectionFactory factory) {
          RedisTemplate<String, T> redisTemplate = new RedisTemplate<>();
          redisTemplate.setConnectionFactory(factory);
          redisTemplate.setKeySerializer(new StringRedisSerializer());
          redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
  
          return redisTemplate;
      }
  
      @Bean
      public RedisMessageListenerContainer redisMessageListenerContainer() {
          RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
          redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
          return redisMessageListenerContainer;
      }
  
      @Bean
      public RedisTemplate<String, byte[]> bytesRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
          RedisTemplate<String, byte[]> template = new RedisTemplate<>();
          template.setKeySerializer(RedisSerializer.string());
          template.setValueSerializer(RedisSerializer.byteArray());
          template.setHashKeySerializer(RedisSerializer.string());
          template.setHashValueSerializer(RedisSerializer.byteArray());
          template.setConnectionFactory(redisConnectionFactory);
          return template;
      }
  
      @Bean
      public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
          RedisTemplate<String, String> template = new RedisTemplate<>();
          template.setKeySerializer(RedisSerializer.string());
          template.setValueSerializer(RedisSerializer.string());
          template.setHashKeySerializer(RedisSerializer.string());
          template.setHashValueSerializer(RedisSerializer.string());
          template.setConnectionFactory(redisConnectionFactory);
          return template;
      }
  
  
  }
  