“Spring Boot 连 Redis Sentinal”的版本间的差异
		
		
		
		
		
		跳到导航
		跳到搜索
		
				
		
		
	
Jihongchang(讨论 | 贡献)  (建立内容为“1”的新页面)  | 
				Jihongchang(讨论 | 贡献)   | 
				||
| 第1行: | 第1行: | ||
| − | 1  | + | 可以配合 [[Redis Sentinel]] 进行测试  | 
| + | |||
| + | === pom.xml ===  | ||
| + | <syntaxhighlight lang="xml">  | ||
| + | <?xml version="1.0" encoding="UTF-8"?>  | ||
| + | <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>  | ||
| + | |||
| + |     <groupId>io.github.jihch</groupId>  | ||
| + |     <artifactId>spring-boot-redis-sentinel</artifactId>  | ||
| + |     <version>1.0-SNAPSHOT</version>  | ||
| + | |||
| + |     <parent>  | ||
| + |         <groupId>org.springframework.boot</groupId>  | ||
| + |         <artifactId>spring-boot-starter-parent</artifactId>  | ||
| + |         <version>2.4.13</version>  | ||
| + |     </parent>  | ||
| + | |||
| + |     <properties>  | ||
| + |         <maven.compiler.source>8</maven.compiler.source>  | ||
| + |         <maven.compiler.target>8</maven.compiler.target>  | ||
| + |     </properties>  | ||
| + | |||
| + |     <dependencies>  | ||
| + |         <dependency>  | ||
| + |             <groupId>org.springframework.boot</groupId>  | ||
| + |             <artifactId>spring-boot-starter-test</artifactId>  | ||
| + |             <scope>test</scope>  | ||
| + |         </dependency>  | ||
| + | |||
| + |         <dependency>  | ||
| + |             <groupId>org.projectlombok</groupId>  | ||
| + |             <artifactId>lombok</artifactId>  | ||
| + |         </dependency>  | ||
| + | |||
| + | |||
| + |         <dependency>  | ||
| + |             <groupId>org.springframework.boot</groupId>  | ||
| + |             <artifactId>spring-boot-starter-data-redis</artifactId>  | ||
| + |         </dependency>  | ||
| + | |||
| + | |||
| + |         <dependency>  | ||
| + |             <groupId>org.springframework.boot</groupId>  | ||
| + |             <artifactId>spring-boot-starter-web</artifactId>  | ||
| + |             <version>2.4.0</version>  | ||
| + |         </dependency>  | ||
| + | |||
| + |         <dependency>  | ||
| + |             <groupId>org.springframework.boot</groupId>  | ||
| + |             <artifactId>spring-boot-configuration-processor</artifactId>  | ||
| + |             <optional>true</optional>  | ||
| + |         </dependency>  | ||
| + | |||
| + |     </dependencies>  | ||
| + | |||
| + | </project>  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | |||
| + | |||
| + | === application.yml ===  | ||
| + | <syntaxhighlight lang="yaml">  | ||
| + | spring:  | ||
| + |   redis:  | ||
| + |     sentinel:  | ||
| + |       master: mymaster # Sentinel 集群名称  | ||
| + |       nodes: 127.0.0.1:5000,127.0.0.1:5001,127.0.0.1:5002 # Sentinel 节点列表  | ||
| + |     password: vn4sj5kbxdaG # Redis 认证密码  | ||
| + | </syntaxhighlight>  | ||
| + | |||
| + | |||
| + | === 代码 ===  | ||
| + | https://github.com/jihch/spring-boot-redis-sentinel  | ||
2023年2月19日 (日) 10:44的最新版本
可以配合 Redis Sentinel 进行测试
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>io.github.jihch</groupId>
    <artifactId>spring-boot-redis-sentinel</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.13</version>
    </parent>
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>
</project>
application.yml
spring:
  redis:
    sentinel:
      master: mymaster # Sentinel 集群名称
      nodes: 127.0.0.1:5000,127.0.0.1:5001,127.0.0.1:5002 # Sentinel 节点列表
    password: vn4sj5kbxdaG # Redis 认证密码