38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package com.yupi.springbootinit.config;
|
|
|
|
|
|
|
|
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;
|
|
|
|
@Configuration
|
|
public class RedisConfig {
|
|
|
|
|
|
@Bean(name="redisTemplate")
|
|
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
|
|
RedisTemplate<String, String> template = new RedisTemplate<>();
|
|
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
|
template.setConnectionFactory(factory);
|
|
//key序列化方式
|
|
template.setKeySerializer(redisSerializer);
|
|
//value序列化
|
|
template.setValueSerializer(redisSerializer);
|
|
//value hashmap序列化
|
|
template.setHashValueSerializer(redisSerializer);
|
|
//key haspmap序列化
|
|
template.setHashKeySerializer(redisSerializer);
|
|
//
|
|
return template;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|