#166 - Rename Redis cluster-sentinel to sentinel.
Rename the Redis cluster-sentinel project to sentinel and leave a hint in the cluster-sentinel directory that points to the Redis Cluster and Redis Sentinel examples mentioning clarifying the cluster-sentinel naming.
This commit is contained in:
28
redis/sentinel/README.md
Normal file
28
redis/sentinel/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Spring Data Redis - Sentinel Examples
|
||||
|
||||
This project contains samples of Sentinel specific features of Spring Data Redis.
|
||||
|
||||
## Support for Sentinel
|
||||
|
||||
```java
|
||||
@Configuration
|
||||
public class RedisSentinelApplicationConfig {
|
||||
|
||||
static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration().master("mymaster") //
|
||||
.sentinel("localhost", 26379) //
|
||||
.sentinel("localhost", 26380) //
|
||||
.sentinel("localhost", 26381);
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory connectionFactory() {
|
||||
return new JedisConnectionFactory(sentinelConfig());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisSentinelConfiguration sentinelConfig() {
|
||||
return SENTINEL_CONFIG;
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
26
redis/sentinel/pom.xml
Normal file
26
redis/sentinel/pom.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-data-redis-sentinel-example</artifactId>
|
||||
<name>Spring Data Redis - Sentinel Example</name>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.data.examples</groupId>
|
||||
<artifactId>spring-data-redis-examples</artifactId>
|
||||
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>spring-data-redis-example-utils</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.redis.sentinel;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisSentinelApplication {
|
||||
|
||||
static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration().master("mymaster") //
|
||||
.sentinel("localhost", 26379) //
|
||||
.sentinel("localhost", 26380) //
|
||||
.sentinel("localhost", 26381);
|
||||
|
||||
@Autowired RedisConnectionFactory factory;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ApplicationContext context = SpringApplication.run(RedisSentinelApplication.class, args);
|
||||
|
||||
StringRedisTemplate template = context.getBean(StringRedisTemplate.class);
|
||||
template.opsForValue().set("loop-forever", "0");
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
|
||||
String value = "IT:= " + template.opsForValue().increment("loop-forever", 1);
|
||||
printBackFromErrorStateInfoIfStopWatchIsRunning(stopWatch);
|
||||
System.out.println(value);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
System.err.println(e.getCause().getMessage());
|
||||
startStopWatchIfNotRunning(stopWatch);
|
||||
}
|
||||
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
public @Bean StringRedisTemplate redisTemplate() {
|
||||
return new StringRedisTemplate(connectionFactory());
|
||||
}
|
||||
|
||||
public @Bean RedisConnectionFactory connectionFactory() {
|
||||
return new JedisConnectionFactory(sentinelConfig());
|
||||
}
|
||||
|
||||
public @Bean RedisSentinelConfiguration sentinelConfig() {
|
||||
return SENTINEL_CONFIG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear database before shut down.
|
||||
*/
|
||||
public @PreDestroy void flushTestDb() {
|
||||
factory.getConnection().flushDb();
|
||||
}
|
||||
|
||||
private static void startStopWatchIfNotRunning(StopWatch stopWatch) {
|
||||
|
||||
if (!stopWatch.isRunning()) {
|
||||
stopWatch.start();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printBackFromErrorStateInfoIfStopWatchIsRunning(StopWatch stopWatch) {
|
||||
|
||||
if (stopWatch.isRunning()) {
|
||||
stopWatch.stop();
|
||||
System.err.println("INFO: Recovered after: " + stopWatch.getLastTaskInfo().getTimeSeconds());
|
||||
}
|
||||
}
|
||||
}
|
||||
1
redis/sentinel/src/main/resources/application.properties
Normal file
1
redis/sentinel/src/main/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
logging.level.root=INFO
|
||||
Reference in New Issue
Block a user