本文整理汇总了Java中org.springframework.data.redis.core.StringRedisTemplate.setValueSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java StringRedisTemplate.setValueSerializer方法的具体用法?Java StringRedisTemplate.setValueSerializer怎么用?Java StringRedisTemplate.setValueSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.redis.core.StringRedisTemplate
的用法示例。
在下文中一共展示了StringRedisTemplate.setValueSerializer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
/**
* RedisTemplate配置
* @param factory
* @return
*/
@Bean
@SuppressWarnings({"rawtypes", "unchecked"})
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
//定义value的序列化方式
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.setHashValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例2: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Bean("redisTemplate") //新家的这个注解 10-26 12:06
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisFactory){
StringRedisTemplate template = new StringRedisTemplate(redisFactory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new
Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例3: getStringRedisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate getStringRedisTemplate() {
StringRedisTemplate clusterTemplate = new StringRedisTemplate();
clusterTemplate.setConnectionFactory(jedisConnectionFactory());
clusterTemplate.setKeySerializer(new StringRedisSerializer());
clusterTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return clusterTemplate;
}
示例4: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked","rawtypes"})
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例5: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例6: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Bean
@SuppressWarnings({ "rawtypes", "unchecked" })
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
StringRedisTemplate template = new StringRedisTemplate(factory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}
示例7: afterPropertiesSet
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
templates = new ArrayList<RedisTemplate>();
List<JedisConnectionFactory> factorys = connectionFactory.getFactories();
for (JedisConnectionFactory factory : factorys) {
StringRedisTemplate template = new StringRedisTemplate(factory);
template.setKeySerializer(keySerializer);
template.setValueSerializer(valueSerializer);
template.setHashKeySerializer(hashKeySerializer);
template.setHashValueSerializer(hashValueSerializer);
// 执行必要方法
template.afterPropertiesSet();
templates.add(template);
}
}
示例8: setSerializer
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
private void setSerializer(StringRedisTemplate template) {
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(
Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
}
示例9: redisTemplate
import org.springframework.data.redis.core.StringRedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(
RedisConnectionFactory redisConnectionFactory) {
logger.info("init redis template...");
StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory);
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
template.setValueSerializer(jackson2JsonRedisSerializer);
template.afterPropertiesSet();
return template;
}