org.springframework.data.redis.connection.RedisSentinelConfiguration Java Examples
The following examples show how to use
org.springframework.data.redis.connection.RedisSentinelConfiguration.
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: CacheCloudInfoHttpHelper.java From summerframework with Apache License 2.0 | 6 votes |
public static RedisSentinelConfiguration getSentinelConfigurationFromCacheCloud(Long appId, String hostUrl) { RedisSentinelConfiguration configuration = null; int i = 0; while (true) { if (i >= 5) { throw new RuntimeException("Can not get info form: " + hostUrl + ". for appId: " + appId + " ."); } try { configuration = generateSentinelConfiguration(appId, hostUrl); TimeUnit.MILLISECONDS.sleep(500 + new Random().nextInt(1000)); return configuration; } catch (Exception e) { LOGGER.error("error in build, appId: {}", appId, e); } i++; } }
Example #2
Source File: CacheCloudInfoHttpHelper.java From summerframework with Apache License 2.0 | 5 votes |
public static RedisSentinelConfiguration generateSentinelConfiguration(Long appId, String hostUrl) { try { LOCK.tryLock(10, TimeUnit.SECONDS); String cachecloudUrl = hostUrl + REDIS_SENTINEL_SUFFIX + CLIENT_VERSION; CACHECLOUD_REPORT_URL = hostUrl + CACHECLOUD_REPORT_URL_PATH; String url = String.format(cachecloudUrl, String.valueOf(appId)); String response = HttpUtils.doGet(String.format(url, appId)); if (response == null || StringUtils.isEmpty(response)) { LOGGER.warn("get response from remote server error, appId: {}, continue...", appId); throw new RuntimeException(); } ObjectMapper mapper = new ObjectMapper(); JsonNode heartbeatInfo = mapper.readTree(response); String masterName = heartbeatInfo.get("masterName").asText(); String sentinels = heartbeatInfo.get("sentinels").asText(); Set<RedisNode> sentinelSet = new HashSet<RedisNode>(); for (String sentinelStr : sentinels.split(" ")) { String[] sentinelArr = sentinelStr.split(":"); if (sentinelArr.length == 2) { sentinelSet.add(new RedisNode(sentinelArr[0], Integer.valueOf(sentinelArr[1]))); } } RedisSentinelConfiguration config = new RedisSentinelConfiguration(); config.master(masterName); config.setSentinels(sentinelSet); ClientDataCollectReportExecutor.getInstance(); return config; } catch (Throwable e) { LOGGER.error("error in build, appId: {}", appId, e); throw new RuntimeException(e); } finally { LOCK.unlock(); } }
Example #3
Source File: RateLimiterPluginDataHandler.java From soul with Apache License 2.0 | 5 votes |
private RedisSentinelConfiguration redisSentinelConfiguration(final RateLimiterConfig rateLimiterConfig) { RedisSentinelConfiguration config = new RedisSentinelConfiguration(); config.master(rateLimiterConfig.getMaster()); config.setSentinels(createRedisNode(rateLimiterConfig.getUrl())); if (rateLimiterConfig.getPassword() != null) { config.setPassword(RedisPassword.of(rateLimiterConfig.getPassword())); } config.setDatabase(rateLimiterConfig.getDatabase()); return config; }
Example #4
Source File: JedisRedisInitializer.java From spring-fu with Apache License 2.0 | 5 votes |
private JedisConnectionFactory getJedisConnectionFactory(GenericApplicationContext context) { final JedisConnectionConfiguration configuration = new JedisConnectionConfiguration(redisProperties, context.getBeanProvider(RedisSentinelConfiguration.class), context.getBeanProvider(RedisClusterConfiguration.class)); try { return configuration.redisConnectionFactory(context.getBeanProvider(JedisClientConfigurationBuilderCustomizer.class)); } catch (UnknownHostException e) { throw new IllegalStateException(e); } }
Example #5
Source File: LettuceRedisInitializer.java From spring-fu with Apache License 2.0 | 5 votes |
private LettuceConnectionFactory getLettuceConnectionFactory(GenericApplicationContext context) { final LettuceConnectionConfiguration configuration = new LettuceConnectionConfiguration(redisProperties, context.getBeanProvider(RedisSentinelConfiguration.class), context.getBeanProvider(RedisClusterConfiguration.class)); final ClientResources clientResources = DefaultClientResources.create(); try { return configuration.redisConnectionFactory(context.getBeanProvider(LettuceClientConfigurationBuilderCustomizer.class), clientResources); } catch (UnknownHostException e) { throw new IllegalStateException(e); } }
Example #6
Source File: MultiCacheAutoConfig.java From gateway-helper with Apache License 2.0 | 5 votes |
public RedisConfig(RedisProperties properties, ObjectProvider<RedisSentinelConfiguration> sentinelConfiguration, ObjectProvider<RedisClusterConfiguration> clusterConfiguration) { this.properties = properties; this.sentinelConfiguration = sentinelConfiguration.getIfAvailable(); this.clusterConfiguration = clusterConfiguration.getIfAvailable(); }
Example #7
Source File: MultiCacheAutoConfig.java From api-gateway-old with Apache License 2.0 | 5 votes |
public RedisConfig(RedisProperties properties, ObjectProvider<RedisSentinelConfiguration> sentinelConfiguration, ObjectProvider<RedisClusterConfiguration> clusterConfiguration) { this.properties = properties; this.sentinelConfiguration = sentinelConfiguration.getIfAvailable(); this.clusterConfiguration = clusterConfiguration.getIfAvailable(); }
Example #8
Source File: SentinelInitializer.java From spring-fu with Apache License 2.0 | 4 votes |
@Override public void initialize(GenericApplicationContext context) { if (sentinel != null) { context.registerBean(RedisSentinelConfiguration.class, this::getRedisSentinelConfiguration); } }
Example #9
Source File: SentinelInitializer.java From spring-fu with Apache License 2.0 | 4 votes |
@NotNull private RedisSentinelConfiguration getRedisSentinelConfiguration() { return new RedisSentinelConfiguration(sentinel.getMaster(), new HashSet<>(sentinel.getNodes())); }
Example #10
Source File: MultiConnectionConfiguration.java From dew with Apache License 2.0 | 4 votes |
public MultiConnectionConfiguration(RedisProperties properties, ObjectProvider<RedisSentinelConfiguration> sentinelConfigurationProvider, ObjectProvider<RedisClusterConfiguration> clusterConfigurationProvider) { super(properties, sentinelConfigurationProvider, clusterConfigurationProvider); }
Example #11
Source File: RedisSentinelApplication.java From spring-data-examples with Apache License 2.0 | 4 votes |
public @Bean RedisSentinelConfiguration sentinelConfig() { return SENTINEL_CONFIG; }
Example #12
Source File: RequiresRedisSentinel.java From spring-data-examples with Apache License 2.0 | 4 votes |
protected RequiresRedisSentinel(RedisSentinelConfiguration config) { this.sentinelConfig = config; }
Example #13
Source File: RequiresRedisSentinel.java From spring-data-examples with Apache License 2.0 | 2 votes |
/** * Create new {@link RequiresRedisSentinel} for given {@link RedisSentinelConfiguration}. * * @param config * @return */ public static RequiresRedisSentinel forConfig(RedisSentinelConfiguration config) { return new RequiresRedisSentinel(config != null ? config : DEFAULT_SENTINEL_CONFIG); }