更新时间:2023-05-06 GMT+08:00
分享

springboot接入

  1. Mas-Redis-SDK使用Maven获取版本,根据实际情况设置Maven远程仓库地址等相关配置。
  2. 在pom.xml文件中引入依赖,下面mas.version版本为最新版本,依赖组件版本参考如何选择组件版本

    <properties>
        <!--以最新的版本号为准-->
        <mas.version>1.3.13-RELEASE</mas.version>
    </properties>
    <dependency>
        <groupId>com.huaweicloud.devspore</groupId>
        <artifactId>spring-cloud-starter-huawei-devspore-dcs</artifactId>
        <version>${mas.version}</version>
    </dependency>

  3. 参考配置文件示例devspore-cache.yaml,配置参数参考参数配置说明

    配置文件示例devspore-cache.yaml:

    devspore:
      dcs:
        props:
          version: v1
          app-id: xxxx
          monitor-id: xxxx
          cloud: xxxx
          region: xxxx
          azs: xxxx 
        etcd: # 可选
          address: xxx.xxx.xxx.xxx:xxxx
          api-version: v3
          username: xxxx
          password: xxxx
          https-enable: false
        active: dc1
        redis:
          servers:
            dc1: // 和mas服务监控页中的名称保持一致:dc1和dc2
              hosts: xxx.xxx.xxx.xxx:xxxx
              password: xxxxxx
              type: normal
              cloud: xxxx
              region: xxxx
              azs: az1
              pool:
                max-total: 8
                max-idle: 8
                min-idle: 8
                max-wait-millis: 10000
                time-between-eviction-runs-millis: 60000
            dc2:
              hosts: xxx.xxx.xxx.xxx:xxxx
              password: xxxxxx
              type: normal
              cloud: xxxx
              region: xxxx
              azs: az1
              pool:
                max-total: 8
                max-idle: 8
                min-idle: 8
                max-wait-millis: 10000
                time-between-eviction-runs-millis: 60000
        route-algorithm: single-read-async-double-write
    

  4. 在需要执行Redis操作的地方引入MultiZoneClient,并使用MultiZoneClient执行Redis操作。

    举例:

    @Autowired
    private MultiZoneClient client;
    
    @Override
    public void set(String key, String value) {
        client.set(key, value);
    }

分享:

    相关文档

    相关产品