use of org.springframework.data.redis.serializer.StringRedisSerializer in project WTFDYUM by jchampemont.
the class RedisConfiguration method featureRedisTemplate.
@Bean
public RedisTemplate<String, Feature> featureRedisTemplate() {
final RedisTemplate<String, Feature> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new EnumRedisSerializer<>(Feature.class));
template.setValueSerializer(new EnumRedisSerializer<>(Feature.class));
return template;
}
use of org.springframework.data.redis.serializer.StringRedisSerializer in project dhis2-core by dhis2.
the class RedisConfiguration method redisTemplate.
@Bean(name = "redisTemplate")
@Primary
public RedisTemplate<?, ?> redisTemplate() {
RedisTemplate<?, ?> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(lettuceConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
return redisTemplate;
}
use of org.springframework.data.redis.serializer.StringRedisSerializer in project cas by apereo.
the class RedisObjectFactory method newRedisTemplate.
/**
* New redis template.
*
* @param <K> the type parameter
* @param <V> the type parameter
* @param connectionFactory the connection factory
* @return the redis template
*/
public static <K, V> CasRedisTemplate<K, V> newRedisTemplate(final RedisConnectionFactory connectionFactory) {
val template = new DefaultCasRedisTemplate<K, V>();
val string = new StringRedisSerializer();
val jdk = new JdkSerializationRedisSerializer();
template.setKeySerializer(string);
template.setValueSerializer(jdk);
template.setHashValueSerializer(jdk);
template.setHashKeySerializer(string);
template.setConnectionFactory(connectionFactory);
return template;
}
use of org.springframework.data.redis.serializer.StringRedisSerializer in project cu-kfs by CU-CommunityApps.
the class CacheConfiguration method redisTemplate.
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory connectionFactory) {
final RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
return redisTemplate;
}
use of org.springframework.data.redis.serializer.StringRedisSerializer in project topcom-cloud by 545314690.
the class RedisConfig method redisTemplate.
/**
* RedisTemplate缓存操作类,类似于jdbcTemplate的一个类;
* <p>
* 虽然CacheManager也能获取到Cache对象,但是操作起来没有那么灵活;
* <p>
* 这里在扩展下:RedisTemplate这个类不见得很好操作,我们可以在进行扩展一个我们
* <p>
* 自己的缓存类,比如:RedisStorage类;
*
* @param factory : 通过Spring进行注入,参数在application.properties进行配置;
* @return
*/
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(factory);
// key序列化方式;(不然会出现乱码;),但是如果方法上有Long等非String类型的话,会报类型转换错误;
// 所以在没有自己定义key生成策略的时候,以下这个代码建议不要这么写,可以不配置或者自己实现ObjectRedisSerializer
// 或者JdkSerializationRedisSerializer序列化方式;
// Long类型不可以会出现异常信息;
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(redisSerializer);
redisTemplate.setHashKeySerializer(redisSerializer);
// 定义value的序列化方式
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.SETTER, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
redisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
redisTemplate.setHashValueSerializer(jackson2JsonRedisSerializer);
return redisTemplate;
}
Aggregations