Redission +spring boot

redission + spring boot

maven



    4.0.0

    com.linseven
    cache
    1.0-SNAPSHOT
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.8.RELEASE
         
    

    
        org.redisson
        redisson
        3.13.1
    
    
        org.springframework.boot
        spring-boot-dependencies
        2.1.8.RELEASE
        pom
        import
    
    
        org.springframework.boot
        spring-boot-starter-web
        2.1.8.RELEASE
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    


    dataCache
    
        
            src/main/java
        
        
            src/main/resources
        
    
    
        
            org.springframework.boot
            spring-boot-maven-plugin
            2.1.8.RELEASE
        
    

Redission +spring boot_第1张图片

application.yml

spring:
    redis:
       redisson:
          config: classpath:redisson.yml
server:
    port: 8080

redisson.yml

clusterServersConfig:
  idleConnectionTimeout: 10000
  connectTimeout: 10000
  timeout: 3000
  retryAttempts: 3
  retryInterval: 1500
  failedSlaveReconnectionInterval: 3000
  failedSlaveCheckInterval: 60000
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  loadBalancer: ! {}
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 50
  slaveConnectionMinimumIdleSize: 24
  slaveConnectionPoolSize: 64
  masterConnectionMinimumIdleSize: 24
  masterConnectionPoolSize: 64
  readMode: "SLAVE"
  subscriptionMode: "SLAVE"
  nodeAddresses:
  - "redis://192.168.43.33:7000"
  - "redis://192.168.43.33:7001"
  - "redis://192.168.43.33:7002"
  - "redis://192.168.43.33:7003"
  - "redis://192.168.43.33:7004"
  - "redis://192.168.43.33:7005"
  scanInterval: 1000
  pingConnectionInterval: 0
  keepAlive: false
  tcpNoDelay: false
threads: 16
nettyThreads: 32
codec: ! {}
transportMode: "NIO"

使用

@RestController
public class TestController {

    @Autowired
    private RedissonClient redisson;
    @GetMapping("/setKey")
    public String setKey(String key,String value){
        RBucket rBucket =  redisson.getBucket(key);
        rBucket.set(value);
        return "success";
    }
    @GetMapping("/getKey")
    public String getKey(String key){
        RBucket rBucket =  redisson.getBucket(key);
        return rBucket.get();

    }

}

集群配置非常重要一点就是需要修改绑定的ip地址为内网地址
192.168.43.33
如果bind 127.0.0.1的话,在局域网将无法访问 192.168.43.33 局域网的redis。
将protected-mode=yes 该为protected-mode=no
1、修改好后需要将安装目录下的
appendonly.aof 、 dump.rdb 、 nodes-7001.conf 删除。
注意删除这个三个文件,仅限于在学习环境,在生产环境不要乱删,应该在应用生产前配置好bind ,protected-mode等正确配置。

你可能感兴趣的:(redis)