本文整理匯總了Java中org.springframework.data.redis.core.RedisTemplate.setConnectionFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java RedisTemplate.setConnectionFactory方法的具體用法?Java RedisTemplate.setConnectionFactory怎麽用?Java RedisTemplate.setConnectionFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.data.redis.core.RedisTemplate
的用法示例。
在下文中一共展示了RedisTemplate.setConnectionFactory方法的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: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: redisTemplateFactory
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate redisTemplateFactory(){
RedisTemplate redisTemplate =new RedisTemplate();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
//指定具體序列化方式 不過這種方式不是很好,一個係統中可能對應值的類型不一樣,如果全部使用StringRedisSerializer 序列化
//會照成其他類型報錯,所以還是推薦使用第一種,直接指定泛型的類型,spring 會根據指定類型序列化。
//redisTemplate.setKeySerializer( new StringRedisSerializer());
//redisTemplate.setValueSerializer(new StringRedisSerializer());
//redisTemplate.setHashKeySerializer(new StringRedisSerializer());
//redisTemplate.setHashValueSerializer(new StringRedisSerializer());
return redisTemplate;
}
示例6: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
RedisTemplate<?, ?> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<byte[], byte[]> template = new RedisTemplate<byte[], byte[]>();
template.setConnectionFactory(connectionFactory);
return template;
}
示例7: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
//使用StringRedisSerializer來序列化和反序列化redis的key值, value值默認會使用JdkSerializationRedisSerializer
template.setKeySerializer(new StringRedisSerializer());
template.afterPropertiesSet();
return template;
}
示例8: 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;
}
示例9: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<String, Object> redisTemplate() {
final RedisTemplate<String, Object> template = new RedisTemplate<String, Object>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
return template;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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);
}
示例13: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean
public RedisTemplate<String, User> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, User> template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisObjectSerializer());
return template;
}
示例14: 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;
}
示例15: redisTemplate
import org.springframework.data.redis.core.RedisTemplate; //導入方法依賴的package包/類
@Bean(name = "redisTemplate")
public RedisTemplate<String, SysUserEntity> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<String, SysUserEntity> template = new RedisTemplate<String, SysUserEntity>();
template.setConnectionFactory(jedisConnectionFactory());
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new RedisObjectSerializer());
return template;
}