Java Code Examples for org.springframework.data.redis.core.StringRedisTemplate#setConnectionFactory()

The following examples show how to use org.springframework.data.redis.core.StringRedisTemplate#setConnectionFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisConfigure.java    From cms with Apache License 2.0 6 votes vote down vote up
/**
 * retemplate相关配置
 *
 * @param factory
 * @return
 */
@Bean
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory factory) {

    StringRedisTemplate template = new StringRedisTemplate();
    // 配置连接工厂
    template.setConnectionFactory(factory);

    //使用StringRedisSerializer来序列化和反序列化redis的key值
    template.setKeySerializer(stringSerializer());
    // 值采用json序列化
    template.setValueSerializer(jackson2JsonRedisSerializer());
    // 设置hash key 和value序列化模式
    template.setHashKeySerializer(stringSerializer());
    template.setHashValueSerializer(jackson2JsonRedisSerializer());

    template.afterPropertiesSet();

    return template;
}
 
Example 2
Source File: SimpleRedisOperationService.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void afterPropertiesSet() throws Exception {
	redisTemplate = createReidsTemplate(jedisConnectionFactory);
	
	StringRedisTemplate template = new StringRedisTemplate();
	template.setConnectionFactory(jedisConnectionFactory);
	template.afterPropertiesSet();
	this.stringRedisTemplate = template;
	
	if (redisCacheManager!=null) {
		expires = (Map<String, Long>) SpringUtils.newPropertyAccessor(redisCacheManager, true).getPropertyValue("expires");
	} else {
		expires = Collections.emptyMap();
	}
}
 
Example 3
Source File: CacheConfig.java    From UserCenter with MIT License 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 4
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 5
Source File: RedissonAutoConfiguration.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(StringRedisTemplate.class)
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setConnectionFactory(redisConnectionFactory);
    return template;
}
 
Example 6
Source File: RedisConfig.java    From ueboot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(type = {"org.springframework.data.redis.core.RedisTemplate"})
public RedisTemplate<?, ?> redisTemplate(
        LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate(redisConnectionFactory);
    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().build(),ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);
    template.setValueSerializer(jackson2JsonRedisSerializer);
    template.setConnectionFactory(redisConnectionFactory);
    template.afterPropertiesSet();
    return template;
}
 
Example 7
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 8
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Bean(name = "userRedisTemplate")
public RedisTemplate userRedisTemplate(@Qualifier("userRedisConnectionFactory") RedisConnectionFactory cf) {
    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(cf);
    setSerializer(stringRedisTemplate);
    return stringRedisTemplate;
}
 
Example 9
Source File: RedisConfig.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(StringRedisTemplate.class)
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setConnectionFactory(redisConnectionFactory);
    log.info("构建 StringRedisTemplate 成功");
    return template;
}
 
Example 10
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
@Bean(name = "stringRedisTemplate3")
public StringRedisTemplate stringRedisTemplate3() throws Exception {
    StringRedisTemplate redisTemplateObject = new StringRedisTemplate();
    redisTemplateObject.setConnectionFactory(jedisConnectionFactory3());
    redisTemplateObject.afterPropertiesSet();
    return redisTemplateObject;
}
 
Example 11
Source File: RedisConfig.java    From SpringBootLearn with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(StringRedisTemplate.class)
public StringRedisTemplate stringRedisTemplate(
        RedisConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setConnectionFactory(redisConnectionFactory);
    return template;
}
 
Example 12
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
@Bean(name = "stringRedisTemplate1")
public StringRedisTemplate stringRedisTemplate1() throws Exception {
    StringRedisTemplate redisTemplateObject = new StringRedisTemplate();
    redisTemplateObject.setConnectionFactory(jedisConnectionFactory1());
    redisTemplateObject.afterPropertiesSet();
    return redisTemplateObject;
}
 
Example 13
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Bean(name = "roleRedisTemplate")
public RedisTemplate roleRedisTemplate(@Qualifier("roleRedisConnectionFactory") RedisConnectionFactory cf) {
    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(cf);
    setSerializer(stringRedisTemplate);
    return stringRedisTemplate;
}
 
Example 14
Source File: RedisConfiguration.java    From ad with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate() {
    StringRedisTemplate redisTemplate = new StringRedisTemplate();
    redisTemplate.setConnectionFactory(lettuceConnectionFactory());
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
 
Example 15
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 16
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 17
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 5 votes vote down vote up
@Bean
public StringRedisTemplate stringRedisTemplate(LettuceConnectionFactory redisConnectionFactory) {
    StringRedisTemplate template = new StringRedisTemplate();
    template.setKeySerializer(new PrefixRedisSerializer());
    template.setValueSerializer(new StringRedisSerializer());
    template.setConnectionFactory(redisConnectionFactory);
    template.setHashKeySerializer(new StringRedisSerializer());
    template.setHashValueSerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
 
Example 18
Source File: RedisConfig.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
@Bean
public RedisTemplate<String, String> redisTemplate() {
    StringRedisTemplate rt = new StringRedisTemplate();
    rt.setConnectionFactory(redisConnectionFactory());
    return rt;
}
 
Example 19
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 4 votes vote down vote up
@Bean(name = "roleStringRedisTemplate")
public StringRedisTemplate roleStringRedisTemplate(@Qualifier("roleRedisConnectionFactory") RedisConnectionFactory cf) {
    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(cf);
    return stringRedisTemplate;
}
 
Example 20
Source File: RedisConfiguration.java    From spring-boot-with-multi-redis with MIT License 4 votes vote down vote up
@Bean(name = "userStringRedisTemplate")
public StringRedisTemplate userStringRedisTemplate(@Qualifier("userRedisConnectionFactory") RedisConnectionFactory cf) {
    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(cf);
    return stringRedisTemplate;
}