com.alibaba.fastjson.support.spring.FastJsonRedisSerializer Java Examples

The following examples show how to use com.alibaba.fastjson.support.spring.FastJsonRedisSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisConfig.java    From Demo with Apache License 2.0 5 votes vote down vote up
@Bean
@SuppressWarnings("unchecked")
public RedisTemplate<String, Object> redisTemplate() {
    RedisSerializer<String> stringSerializer = new StringRedisSerializer();
    //RedisSerializer<Object> jsonString = new GenericToStringSerializer<>(Object.class);
    RedisSerializer<Object> jsonString = new FastJsonRedisSerializer<>(Object.class);
    // String 的 key 和 hash 的 key 都采用 String 的序列化方式
    redisTemplate.setKeySerializer(stringSerializer);
    redisTemplate.setHashKeySerializer(stringSerializer);
    // value 都采用 fastjson 的序列化方式
    redisTemplate.setValueSerializer(jsonString);
    redisTemplate.setHashValueSerializer(jsonString);
    return redisTemplate;
}
 
Example #2
Source File: RedisConfig.java    From AnyMock with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisTemplate<String, HttpInterfaceBO> httpInterfaceRedisTemplate() {
    RedisTemplate<String, HttpInterfaceBO> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(redisConnectionFactory);
    redisTemplate.setDefaultSerializer(new FastJsonRedisSerializer<>(String.class));
    redisTemplate.setValueSerializer(new FastJsonRedisSerializer<>(HttpInterfaceBO.class));
    return redisTemplate;
}