package com.zcxk.core.utils.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.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @Description: utils config
 * @Copyright: Copyright (c) 2020 ishare.com
 * @Author: liu.yong
 * @Date : 2020/3/5 17:26
 * @Version: V 1.0.0
 */
@Configuration
class RedisConfig {

   @Bean("redisWithSerial")
   RedisTemplate<Object, Object> getRedisTemplate(
       RedisTemplate<Object, Object> redisTemplate) {
      //设置序列化Key的实例化对象
      StringRedisSerializer keySerializer = new StringRedisSerializer();
      redisTemplate.setKeySerializer(keySerializer);
      redisTemplate.setHashKeySerializer(keySerializer);
      GenericFastJsonRedisSerializer valueSerializer = new GenericFastJsonRedisSerializer();
      redisTemplate.setValueSerializer(valueSerializer);
      redisTemplate.setHashValueSerializer(valueSerializer);
      return redisTemplate;
   }
}
