SpringBoot redis 보초병 모드 사용

5895 단어 자바SpringBootredis
1. pom. xm 파일 설정

      4.0.0
      szw
      springboot_redis_sentinel
      0.0.1-SNAPSHOT
      springboot_redis_sentinel
      springboot  redis  
  
      
        UTF-8
        UTF-8
        1.8
        com.sicdt.sicsign.web.SicSignWebApplication
    
  
      
        org.springframework.boot
        spring-boot-starter-parent
        1.4.2.RELEASE
        
    
    
    
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.boot
            spring-boot-starter-aop
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-redis
        
    
    
    
    
        
            releases
            Releases
            http://192.168.3.71:8081/nexus/content/repositories/releases/
        
        
            snapshots
            Snapshots
            http://192.168.3.71:8081/nexus/content/repositories/snapshots/
        
    

    
    
        
            sicdt
            Sicdt
            http://192.168.3.71:8081/nexus/content/groups/public
        
        
            spring-releases
            https://repo.spring.io/libs-release
        
    
    
        
            spring-releases
            https://repo.spring.io/libs-release
        
    
    
      
         
              
              
                org.apache.maven.plugins  
                maven-source-plugin  
                  
                    true  
                  
                  
                      
                        compile  
                          
                            jar  
                          
                      
                  
            
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    true
                
              
          
    

2. application. properties 설정
##    
spring.redis.host=39.107.119.256
##   
spring.redis.port=6381
##         (          ) 
spring.redis.pool.max-active=300
## Redis     (   0) 
spring.redis.database=0
##            (          ) 
spring.redis.pool.max-wait=-1
##             
spring.redis.pool.max-idle=100
##             
spring.redis.pool.min-idle=20
##       (  ) 
spring.redis.timeout=60000

#         
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=39.107.119.256:26379

3. 시작 클래스
package com.szw.redis;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SzwRedisApplication {
    public static void main(String[] args) {
        System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(SzwRedisApplication.class, args);
    }
}

4. 유닛 테스트 클래스
package com.sze.redis;

import javax.annotation.PostConstruct;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class SentinelTest {
    
    @Autowired
    StringRedisTemplate redisTemplate;
    
    ValueOperations stringRedis;
    
    @PostConstruct
    public void init(){
        stringRedis=redisTemplate.opsForValue();
    }
    
    
    @Test
    public void testString (){
        stringRedis.set("name", "zz");
        System.out.println(stringRedis.get("name"));
    }
}

좋은 웹페이지 즐겨찾기