org.springframework.boot.autoconfigure.data.redis.RedisProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.data.redis.RedisProperties. 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: RedisConfUtils.java    From storm_spring_boot_demo with MIT License 7 votes vote down vote up
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;
}
 
Example #2
Source File: RedisConfig.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public RedisProperties dataSourceProperties() {
    RedisProperties properties = new RedisProperties();
    final String serviceId = environment.getProperty(REDIS_SERVICE_ID);
    if (loadBalancerClient != null && serviceId != null) {
        // also, we can choose redis sentinel system, or wait redis cluster (see https://jira.spring.io/browse/DATAREDIS-315)
        final ServiceInstance infos = loadBalancerClient.choose(serviceId);
        if (infos != null) {
            fillFields(infos, properties);
            LOGGER.info("registered redis from cloud {}:{}", infos.getHost(), infos.getPort());
        } else {
            LOGGER.warn("there is no services with id {} in service discovery", serviceId);
        }
    }
    return properties;
}
 
Example #3
Source File: RedisRateLimiterConfiguration.java    From daming with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(value = RequestRateLimiterFactory.class)
public RedisRateLimiterFactory redisRateLimiterFactory(ClientResources redisClientResources, RedisProperties redisProperties) {
    RedisURI.Builder builder = RedisURI.builder()
            .withHost(redisProperties.getHost())
            .withPort(redisProperties.getPort());
    if (!StringUtils.isEmpty(redisProperties.getPassword())) {
        builder = builder.withPassword(redisProperties.getPassword());
    }
    if (null != redisProperties.getTimeout()) {
        builder = builder.withTimeout(redisProperties.getTimeout());
    }
    builder = builder.withDatabase(redisProperties.getDatabase())
            .withSsl(redisProperties.isSsl());
    RedisURI redisUri = builder.build();
    return new RedisRateLimiterFactory(RedisClient.create(redisClientResources, redisUri));
}
 
Example #4
Source File: MultiCacheAutoConfig.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
public RedisConfig(RedisProperties properties,
                   ObjectProvider<RedisSentinelConfiguration> sentinelConfiguration,
                   ObjectProvider<RedisClusterConfiguration> clusterConfiguration) {
    this.properties = properties;
    this.sentinelConfiguration = sentinelConfiguration.getIfAvailable();
    this.clusterConfiguration = clusterConfiguration.getIfAvailable();
}
 
Example #5
Source File: CommonsAutoConfiguration.java    From platform with Apache License 2.0 5 votes vote down vote up
public CommonsAutoConfiguration(CommonsProperties commonsProperties, RedisProperties redisProperties) {
    Assert.notNull(commonsProperties, "CommonsProperties must not be null!");
    Assert.notNull(redisProperties, "RedisProperties must not be null!");

    this.commonsProperties = commonsProperties;
    this.redisProperties = redisProperties;
}
 
Example #6
Source File: RedisConfUtils.java    From storm_spring_boot_demo with MIT License 5 votes vote down vote up
/**
 * {@link org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration#getClusterConfiguration}
 * @param redisProperties
 * @return
 */
public static RedisClusterConfiguration  getClusterConfiguration(RedisProperties redisProperties) {
    if (redisProperties.getCluster() == null) {
        return null;
    }
    RedisProperties.Cluster clusterProperties = redisProperties.getCluster();
    RedisClusterConfiguration config = new RedisClusterConfiguration(
            clusterProperties.getNodes());

    if (clusterProperties.getMaxRedirects() != null) {
        config.setMaxRedirects(clusterProperties.getMaxRedirects());
    }
    return config;
}
 
Example #7
Source File: RedisConfig.java    From ueboot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * spring boot 2.0后采用Lettuce作为redis调用客户端
 * 默认配置只支持单机模式,如需要其他模式,需要另外定义
 *
 * @return LettuceConnectionFactory
 */
@Bean
@ConditionalOnMissingBean(type = {"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"})
public LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisProperties.getHost(),
            redisProperties.getPort());
    configuration.setDatabase(redisProperties.getDatabase());
    configuration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    return new LettuceConnectionFactory(configuration);
}
 
Example #8
Source File: MultiCacheAutoConfig.java    From gateway-helper with Apache License 2.0 5 votes vote down vote up
public RedisConfig(RedisProperties properties,
                   ObjectProvider<RedisSentinelConfiguration> sentinelConfiguration,
                   ObjectProvider<RedisClusterConfiguration> clusterConfiguration) {
    this.properties = properties;
    this.sentinelConfiguration = sentinelConfiguration.getIfAvailable();
    this.clusterConfiguration = clusterConfiguration.getIfAvailable();
}
 
Example #9
Source File: RedisConfig.java    From hot-crawler with MIT License 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory()
{
    RedisProperties properties = redisProperties();
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(properties.getHost());
    configuration.setPort(properties.getPort());
    configuration.setPassword(properties.getPassword());
    configuration.setDatabase(properties.getDatabase());
    return new JedisConnectionFactory(configuration);
}
 
Example #10
Source File: BeihuRedissonConfiguration.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public RedissonClient getRedisson() {

    Config config = new Config();

    if (redisProperties.getSentinel() != null) {
        RedisProperties.Sentinel sentinel = redisProperties.getSentinel();
        config.useSentinelServers()
                .setDatabase(redisProperties.getDatabase())
                .setMasterName(sentinel.getMaster())
                .addSentinelAddress(formatNodes(sentinel.getNodes()))
                .setPassword(redisProperties.getPassword());
    } else if (redisProperties.getCluster() != null) {
        RedisProperties.Cluster cluster = redisProperties.getCluster();
        config.useClusterServers()
                .addNodeAddress(formatNodes(cluster.getNodes()))
                .setPassword(redisProperties.getPassword());
    } else if (StringUtils.hasText(redisProperties.getUrl())) {
        config.useSingleServer().setAddress(redisProperties.getUrl())
                .setPassword(redisProperties.getPassword());
    } else {
        config.useSingleServer()
                .setAddress(MessageFormat.format("redis://{0}:{1}",
                        redisProperties.getHost(), String.valueOf(redisProperties.getPort())))
                .setPassword(redisProperties.getPassword());
    }
    return Redisson.create(config);
}
 
Example #11
Source File: RedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveRedisConnectionFactory reactiveRedisConnectionFactory(RedisProperties redisProperties) {
	RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort());
	redisStandaloneConfiguration.setPassword(redisProperties.getPassword());
	return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
 
Example #12
Source File: RedisConfiguration.java    From spring-boot-seed with MIT License 4 votes vote down vote up
@Autowired
public RedisConfiguration(RedisProperties properties) {
    this.properties = properties;
}
 
Example #13
Source File: BeihuRedissonConfiguration.java    From beihu-boot with Apache License 2.0 4 votes vote down vote up
public BeihuRedissonConfiguration(RedisProperties redisProperties) {
    this.redisProperties = redisProperties;
}
 
Example #14
Source File: FastDepRedisProperties.java    From fastdep with Apache License 2.0 4 votes vote down vote up
public void setRedis(Map<String, RedisProperties> redis) {
    this.redis = redis;
}
 
Example #15
Source File: RedisConfiguration.java    From galeb with Apache License 2.0 4 votes vote down vote up
@Bean
@Primary
public RedisProperties redisProperties() {
    return new RedisProperties();
}
 
Example #16
Source File: FastDepRedisProperties.java    From fastdep with Apache License 2.0 4 votes vote down vote up
public Map<String, RedisProperties> getRedis() {
    return redis;
}
 
Example #17
Source File: RedisConfig.java    From hot-crawler with MIT License 4 votes vote down vote up
@Bean
@Primary
public RedisProperties redisProperties() {
    return new RedisProperties();
}
 
Example #18
Source File: RedisConfig.java    From haven-platform with Apache License 2.0 4 votes vote down vote up
private void fillFields(ServiceInstance serviceInstance, RedisProperties properties) {
    properties.setHost(serviceInstance.getHost());
    properties.setPort(serviceInstance.getPort());
}
 
Example #19
Source File: MultiRedisConfig.java    From dew with Apache License 2.0 2 votes vote down vote up
/**
 * Gets multi.
 *
 * @return the multi
 */
public Map<String, RedisProperties> getMulti() {
    return multi;
}
 
Example #20
Source File: MultiRedisConfig.java    From dew with Apache License 2.0 2 votes vote down vote up
/**
 * Sets multi.
 *
 * @param multi the multi
 */
public void setMulti(Map<String, RedisProperties> multi) {
    this.multi = multi;
}