本文整理汇总了Java中org.springframework.data.redis.core.RedisTemplate.setHashKeySerializer方法的典型用法代码示例。如果您正苦于以下问题:Java RedisTemplate.setHashKeySerializer方法的具体用法?Java RedisTemplate.setHashKeySerializer怎么用?Java RedisTemplate.setHashKeySerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.redis.core.RedisTemplate
的用法示例。
在下文中一共展示了RedisTemplate.setHashKeySerializer方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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;
}
示例7: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate<Object, Object> redisTemplate() {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory());
template.setHashKeySerializer(new GenericToStringSerializer<>(UUID.class));
template.setKeySerializer(new GenericToStringSerializer<>(UUID.class));
template.setHashValueSerializer(new GenericToStringSerializer<>(Object.class));
template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return template;
}
示例8: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //导入方法依赖的package包/类
@Bean
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate template = new RedisTemplate();
template.setConnectionFactory(factory);
RedisSerializer keySerializer = new StringRedisSerializer();
// 设置key序列化类,否则key前面会多了一些乱码
template.setKeySerializer(keySerializer);
template.setHashKeySerializer(keySerializer);
// FIXME 有些版本有bug,没有序列化的只能序列化,但无法反序列化
GenericJackson2JsonRedisSerializer jsonSerializer = new GenericJackson2JsonRedisSerializer();
// 设置内容序列化类
template.setValueSerializer(jsonSerializer);
template.afterPropertiesSet();
return template;
}