本文整理汇总了Java中org.springframework.data.redis.core.RedisTemplate.setKeySerializer方法的典型用法代码示例。如果您正苦于以下问题:Java RedisTemplate.setKeySerializer方法的具体用法?Java RedisTemplate.setKeySerializer怎么用?Java RedisTemplate.setKeySerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.redis.core.RedisTemplate
的用法示例。
在下文中一共展示了RedisTemplate.setKeySerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, String> template = new RedisTemplate<>();
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
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.setConnectionFactory(factory);
//key序列化方式
template.setKeySerializer(redisSerializer);
//value序列化
template.setValueSerializer(jackson2JsonRedisSerializer);
//value hashmap序列化
template.setHashValueSerializer(jackson2JsonRedisSerializer);
return template;
}
示例2: buildRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
public static RedisTemplate buildRedisTemplate(byte[] redisProperties){
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(
RedisConfUtils.getClusterConfiguration(
(RedisProperties) Serializer.INSTANCE.deserialize(redisProperties)));
RedisTemplate<String, Long> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory);
jedisConnectionFactory.afterPropertiesSet();
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
redisTemplate.setKeySerializer(stringRedisSerializer);
redisTemplate.setValueSerializer(genericJackson2JsonRedisSerializer);
redisTemplate.setHashKeySerializer(stringRedisSerializer);
redisTemplate.setHashValueSerializer(genericJackson2JsonRedisSerializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
示例3: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
@Primary
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory rcf) {
AitLogger.debug(logger, "Serializer overriding ");
RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(rcf);
GenericJackson2JsonRedisSerializer valSerializer = new GenericJackson2JsonRedisSerializer();
template.setValueSerializer(valSerializer);
template.setKeySerializer(new RedisSerializer<Object>() {
@Override
public byte[] serialize(Object t) throws SerializationException {
return (t == null ? null : (":" + t.toString()).getBytes());
}
@Override
public Object deserialize(byte[] bytes) throws SerializationException {
return (bytes == null ? null : new String(bytes));
}
});
template.setHashValueSerializer(valSerializer);
return template;
}
示例4: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
//使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(mapper);
template.setValueSerializer(serializer);
//使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
示例5: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean(name = "redisTemplate")
public RedisTemplate<String,?> redisTemplate(@Qualifier("mafConnectionFactory") RedisConnectionFactory factory) {
RedisTemplate<String,?> template = new RedisTemplate<>();
template.setConnectionFactory(factory);
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
示例6: jsonRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
private RedisTemplate jsonRedisTemplate(JedisConnectionFactory jedisConnectionFactory, Class<?> clazz) {
RedisTemplate template = new RedisTemplate();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new Jackson2JsonRedisSerializer(clazz));
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new Jackson2JsonRedisSerializer(clazz));
template.setConnectionFactory(jedisConnectionFactory);
return template;
}
示例7: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public <K, V> RedisTemplate<K, V> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<K, V> template = new RedisTemplate<>();
template.setConnectionFactory(redisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
return template;
}
示例8: redisListTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean(name = "redisListTemplate")
RedisTemplate<String, Long> redisListTemplate() {
RedisTemplate<String, Long> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericToStringSerializer<>(Long.class));
return redisTemplate;
}
示例9: redisCountingTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean(name = "redisCountingTemplate")
RedisTemplate<String, Integer> redisCountingTemplate() {
RedisTemplate<String, Integer> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new GenericToStringSerializer<>(Integer.class));
return redisTemplate;
}
示例10: initRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
/**
* 序列化设置
*/
private void initRedisTemplate(RedisTemplate<String, String> redisTemplate, RedisConnectionFactory factory) {
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setConnectionFactory(factory);
}
示例11: createCacheRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
private RedisTemplate<String, String> createCacheRedisTemplate(final RedisConnectionFactory redisConnectionFactory,
final String redisTemplateType) {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setDefaultSerializer(new StringRedisSerializer());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
LOGGER.info("Successfully created {} Redis template.", redisTemplateType);
return redisTemplate;
}
示例12: getRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean("redisTemplate")
public RedisTemplate<?, ?> getRedisTemplate(){
RedisTemplate<?,?> template = new StringRedisTemplate(jedisConnectionFactory);
GenericJackson2JsonRedisSerializer genericJackson2JsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
template.setKeySerializer(stringRedisSerializer);
template.setValueSerializer(genericJackson2JsonRedisSerializer);
template.setHashKeySerializer(stringRedisSerializer);
template.setHashValueSerializer(genericJackson2JsonRedisSerializer);
return template;
}
示例13: byteRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate byteRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setEnableDefaultSerializer(true);
//redisTemplate.setDefaultSerializer(new StringRedisSerializer());
redisTemplate.setKeySerializer(new StringRedisSerializer());
//redisTemplate.setValueSerializer(new StringRedisSerializer());
//redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
示例14: stringRedisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate redisTemplate = new RedisTemplate();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setEnableDefaultSerializer(true);
redisTemplate.setDefaultSerializer(new StringRedisSerializer());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
//redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
示例15: setSerializer
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void setSerializer(RedisTemplate<String, Object> 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.setKeySerializer(new StringRedisSerializer());
//template.setValueSerializer(jackson2JsonRedisSerializer); //-- 值序列化为json
template.setValueSerializer(new RedisObjectSerializer()); //-- 默认序列化为byte[]
}