当前位置: 首页>>代码示例>>Java>>正文


Java RedisTemplate.setConnectionFactory方法代码示例

本文整理汇总了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;
}
 
开发者ID:cwenao,项目名称:springboot_cwenao,代码行数:25,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:allianzit,项目名称:ait-platform,代码行数:27,代码来源:AitCacheConfigBase.java

示例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;
}
 
开发者ID:finefuture,项目名称:data-migration,代码行数:20,代码来源:RedisConfiguration.java

示例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;
}
 
开发者ID:veritasware,项目名称:neto,代码行数:10,代码来源:AppConfig.java

示例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;
}
 
开发者ID:1991wangliang,项目名称:tx-lcn,代码行数:14,代码来源:JedisClusterConfig.java

示例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;
}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:9,代码来源:ApplicationConfiguration.java

示例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;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:10,代码来源:MessageConverterConfig.java

示例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;
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:13,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:michaelcgood,项目名称:spring-data-redis-example,代码行数:8,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:9,代码来源:RedisConfiguration.java

示例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;
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:10,代码来源:RedisConfiguration.java

示例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);
}
 
开发者ID:SnackMen,项目名称:DanmuChat,代码行数:11,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:nellochen,项目名称:springboot-start,代码行数:9,代码来源:RedisConfig.java

示例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;
}
 
开发者ID:eclipse,项目名称:keti,代码行数:11,代码来源:CommonRedisConfig.java

示例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;
}
 
开发者ID:guolf,项目名称:pds,代码行数:9,代码来源:RedisConfig.java


注:本文中的org.springframework.data.redis.core.RedisTemplate.setConnectionFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。