content: package ljl.bilibili.search.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.serializer.RedisSerializer;
  import org.springframework.data.redis.serializer.StringRedisSerializer;
  
  import java.util.List;
  
  /**
   * redis的配置类
   */
  @Configuration
  public class RedisConfig {
  
  
  
      @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;
      }
  
  
      @Bean
      public RedisTemplate<String, Object> objectRedisTemplate(RedisConnectionFactory factory) {
          RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
          redisTemplate.setConnectionFactory(factory);
          redisTemplate.setKeySerializer(new StringRedisSerializer());
          redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
  
          return redisTemplate;
      }
  
  
      @Bean
      public RedisTemplate<String, List<Object>> listRedisTemplate(RedisConnectionFactory factory) {
          RedisTemplate<String, List<Object>> redisTemplate = new RedisTemplate<>();
          redisTemplate.setConnectionFactory(factory);
          redisTemplate.setKeySerializer(new StringRedisSerializer());
          redisTemplate.setValueSerializer(new GenericFastJsonRedisSerializer());
          return redisTemplate;
      }
  
  }