Search in sources :

Example 1 with GenericToStringSerializer

use of org.springframework.data.redis.serializer.GenericToStringSerializer in project moon by gentoo111.

the class RedisConfig method redisTemplate.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Bean("redisTemplate")
public RedisTemplate redisTemplate(@Lazy RedisConnectionFactory connectionFactory) {
    RedisTemplate redis = new RedisTemplate();
    GenericToStringSerializer<String> keySerializer = new GenericToStringSerializer<String>(String.class);
    redis.setKeySerializer(keySerializer);
    redis.setHashKeySerializer(keySerializer);
    GenericJackson2JsonRedisSerializer valueSerializer = new GenericJackson2JsonRedisSerializer();
    redis.setValueSerializer(valueSerializer);
    redis.setHashValueSerializer(valueSerializer);
    redis.setConnectionFactory(connectionFactory);
    return redis;
}
Also used : GenericJackson2JsonRedisSerializer(org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) GenericToStringSerializer(org.springframework.data.redis.serializer.GenericToStringSerializer) Bean(org.springframework.context.annotation.Bean)

Aggregations

Bean (org.springframework.context.annotation.Bean)1 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)1 GenericJackson2JsonRedisSerializer (org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer)1 GenericToStringSerializer (org.springframework.data.redis.serializer.GenericToStringSerializer)1