更新时间:2025-08-05 GMT+08:00

查询所有实例列表

功能介绍

查询租户的缓存实例列表,支持按照条件查询。

调用方法

请参见如何调用API

URI

GET /v2/{project_id}/instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释

项目ID。获取方法请参见获取项目ID

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

表2 Query参数

参数

是否必选

参数类型

描述

instance_id

String

参数解释

实例ID。可通过DCS控制台进入实例详情界面查看。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

include_failure

String

参数解释

是否返回创建失败的实例数。

约束限制

不涉及。

取值范围

  • true:返回创建失败的实例数。

  • false:不返回创建失败的实例数。

默认取值

false

include_delete

String

参数解释

是否返回已删除的实例数。

约束限制

不涉及。

取值范围

  • true:返回已删除的实例数。

  • false:不返回已删除的实例数。

默认取值

false

name

String

参数解释

实例名称。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

offset

Integer

参数解释

偏移量,表示生成的列表从此偏移量开始显示,例如偏移量为3时,生成的列表从第4条开始。

约束限制

不涉及。

取值范围

大于等于0。

默认取值

0

limit

Integer

参数解释

每页显示的条目数量。

约束限制

不涉及。

取值范围

1-1000

默认取值

10

status

String

参数解释

实例状态。

约束限制

不涉及。

取值范围

详细状态说明见缓存实例状态说明

默认取值

不涉及。

name_equal

String

参数解释

按照实例名称进行精确匹配查询。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

tags

String

参数解释

根据实例标签键值对进行查询。{key}表示标签键,{value}表示标签值。

约束限制

如果同时使用多个标签键值对进行查询,中间使用逗号分隔开,表示查询同时包含指定标签键值对的实例。

取值范围

不涉及。

默认取值

不涉及。

ip

String

参数解释

连接缓存实例的IP地址,如192.168.7.146。可以通过DCS控制台进入实例详情界面查看。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

capacity

String

参数解释

缓存实例的容量,单位:GB。

约束限制

不涉及。

取值范围

不涉及。

默认取值

不涉及。

is_recycle

Boolean

参数解释

是否查询回收站的实例。

约束限制

不涉及。

取值范围

  • true:返回回收站的实例。

  • false:返回缓存实例列表。

默认取值

false

请求参数

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

instance_num

Integer

参数解释

实例个数。

取值范围

不涉及。

instances

Array of InstanceListInfo objects

参数解释

实例的详情数组。

取值范围

不涉及。

表4 InstanceListInfo

参数

参数类型

描述

publicip_id

String

参数解释

Redis缓存实例绑定的弹性IP地址的ID。

如果未开启公网访问功能,该字段值为null。

取值范围

不涉及。

vpc_name

String

参数解释

VPC的名称。

取值范围

不涉及。

charging_mode

Integer

参数解释

计费模式。

取值范围

  • 0:按需计费。

  • 1:包年/包月计费。

vpc_id

String

参数解释

Redis缓存实例所在的虚拟私有云ID。

取值范围

不涉及。

subnet_id

String

参数解释

Redis缓存实例绑定的子网ID。

取值范围

不涉及。

security_group_id

String

参数解释

Redis缓存实例绑定的安全组ID。

取值范围

不涉及。

created_at

String

参数解释

实例的创建时间。格式为:2017-03-31T12:24:46.297Z。

取值范围

不涉及。

updated_at

String

参数解释

实例的更新时间。格式为:2017-03-31T19:24:46.297Z。

取值范围

不涉及。

enable_ssl

Boolean

参数解释

Redis缓存实例开启公网访问功能时,是否选择开启SSL。

取值范围

  • true:开启

  • false:不开启

max_memory

Integer

参数解释

实例的总内存大小,单位:MB。

取值范围

不涉及。

used_memory

Integer

参数解释

实例已使用的内存大小,单位:MB。

取值范围

不涉及。

publicip_address

String

参数解释

Redis缓存实例绑定的弹性IP地址。

如果未开启公网访问功能,该字段值为null。

取值范围

不涉及。

capacity

Integer

参数解释

实例的缓存容量规格大小,单位:GB。

取值范围

不涉及。

capacity_minor

String

参数解释

小于1GB规格缓存实例的容量,单位:GB。

取值范围

不涉及。

order_id

String

参数解释

订单ID,按需实例时此值为null。

取值范围

不涉及。

maintain_begin

String

参数解释

维护时间窗开始时间,为UTC时间,格式为HH:mm:ss。

取值范围

不涉及。

maintain_end

String

参数解释

维护时间窗结束时间,为UTC时间,格式为HH:mm:ss。

取值范围

不涉及。

engine

String

参数解释

缓存引擎。

取值范围

  • Redis

  • Memcached

engine_version

String

参数解释

缓存版本。

取值范围

Redis缓存引擎的取值范围如下:

  • 3.0

  • 4.0

  • 5.0

  • 6.0

  • 7.0

当缓存引擎为Memcached时,取值为空。

service_upgrade

Boolean

参数解释

实例是否存在升级任务。

取值范围

  • true:存在

  • false:不存在

no_password_access

String

参数解释

是否允许免密码访问缓存实例。

取值范围

  • true:该实例无需密码即可访问。

  • false:该实例必须通过密码认证才能访问。

service_task_id

String

参数解释

升级任务的ID。

  • 当service_upgrade为true时,为升级任务的ID。

  • 当service_upgrade为false时,该参数为空。

取值范围

不涉及。

ip

String

参数解释

连接缓存实例的IP地址。如果是集群实例,返回多个IP地址,使用逗号分隔。如:192.168.0.1,192.168.0.2。

取值范围

不涉及。

access_user

String

参数解释

通过密码认证访问缓存实例的认证用户名。

取值范围

不涉及。

instance_id

String

参数解释

实例ID。

取值范围

不涉及。

enable_publicip

Boolean

参数解释

Redis 3.0缓存实例是否开启公网访问功能。

取值范围

  • true:开启

  • false:不开启

port

Integer

参数解释

连接缓存实例的端口号。

取值范围

不涉及。

user_id

String

参数解释

实例所在的用户ID。

取值范围

不涉及。

user_name

String

参数解释

实例所在的用户名。

取值范围

不涉及。

domain_name

String

参数解释

实例的域名。

取值范围

不涉及。

readonly_domain_name

String

参数解释

实例的只读域名,只有主备实例有该字段。

取值范围

不涉及。

name

String

参数解释

实例名称。

取值范围

不涉及。

spec_code

String

参数解释

产品规格编码。

取值范围

不涉及。

status

String

参数解释

实例状态。

取值范围

详细状态说明见缓存实例状态说明

tags

Array of ResourceTags objects

参数解释

实例标签键值。

取值范围

不涉及。

enterprise_project_id

String

参数解释

企业项目ID。

取值范围

不涉及。

description

String

参数解释

实例描述信息。

取值范围

不涉及。

cpu_type

String

参数解释

实例CPU类型。

取值范围

  • x86_64:x86计算

  • aarch64:Arm计算

az_codes

Array of strings

参数解释

有资源的可用区编码。

取值范围

不涉及。

features

Features object

参数解释

实例支持特性。

取值范围

不涉及。

sub_status

String

参数解释

实例子状态。

取值范围

不涉及。

deleted_time

String

参数解释

实例的删除时间,仅回收站实例展示。格式为:2017-03-31T19:24:46.297Z。

取值范围

不涉及。

release_time

String

参数解释

实例在回收站的预计释放时间,仅回收站实例展示。格式为:2017-03-31T19:24:46.297Z。

取值范围

不涉及。

available_zones

Array of strings

参数解释

有资源的可用区ID,仅回收站实例展示。

backup_id

String

参数解释

备份ID,仅回收站实例展示。

取值范围

不涉及。

instance_backup_policy

InstanceBackupPolicy object

参数解释

备份策略,实例类型为主备和集群时支持,仅回收站实例展示。

取值范围

不涉及。

cache_mode

String

参数解释

缓存实例类型,仅回收站实例展示。

取值范围

  • single:表示单机实例。

  • ha:表示主备实例。

  • cluster:表示cluster集群实例。

  • proxy:表示Proxy集群实例。

  • ha_rw_split:表示读写分离实例。

enable_ipv6

Boolean

参数解释

是否开启ipv4/ipv6双栈访问,仅回收站实例展示。

取值范围

true:开启ipv4/ipv6双栈访问。

false:不开启

rename_commands

RenameCommandResp object

参数解释

命令重命名列表,仅回收站实例展示。

表5 ResourceTags

参数

参数类型

描述

key

String

参数解释

标签键。

取值范围

不涉及。

value

String

参数解释

标签值。

取值范围

不涉及。

表6 Features

参数

参数类型

描述

support_acl

Boolean

参数解释

实例是否支持ACL。

取值范围

  • true:是

  • false:否

support_transparent_client_ip

Boolean

参数解释

实例是否支持客户端IP透传。

取值范围

  • true:是

  • false:否

support_ssl

Boolean

参数解释

实例是否支持SSL。

取值范围

  • true:是

  • false:否

support_acl_read_policy

Boolean

参数解释

实例是否支持ACL只读路由策略。

取值范围

  • true:是

  • false:否

support_audit_log

Boolean

参数解释

实例是否支持审计日志。

取值范围

  • true:是

  • false:否

表7 InstanceBackupPolicy

参数

参数类型

描述

backup_policy_id

String

参数解释

备份策略ID。

取值范围

不涉及。

created_at

String

参数解释

创建时间。格式为:2022-04-11T09:45:24.790Z。

取值范围

不涉及。

updated_at

String

参数解释

更新时间。格式为:2022-04-12T02:22:03.269Z。

取值范围

不涉及。

policy

BackupPolicyResp object

参数解释

备份策略。

取值范围

不涉及。

tenant_id

String

参数解释

租户ID。

取值范围

不涉及。

表8 BackupPolicyResp

参数

参数类型

描述

backup_type

String

参数解释

备份类型。

取值范围

  • auto:自动备份。

  • manual:手动备份。

save_days

Integer

参数解释

保留天数,单位:天。由自动备份切换为手动备份时,保留自动备份策略信息。

取值范围

1-7

periodical_backup_plan

BackupPlan object

参数解释

备份计划。由自动备份切换为手动备份时,保留自动备份策略信息。

取值范围

不涉及。

表9 BackupPlan

参数

参数类型

描述

timezone_offset

String

参数解释

备份的时区。该参数已废弃,没有实际作用。

取值范围

不涉及。

backup_at

Array of integers

参数解释

每周的周几开始备份。由自动切换为手动时,保留自动备份策略信息。

取值范围

1-7,分别表示星期一到星期日。

period_type

String

参数解释

备份周期类型,目前支持“weekly”。由自动切换为手动时,保留自动备份策略信息。

取值范围

不涉及。

begin_at

String

参数解释

备份开始执行时间,该时间为UTC时间,例如“00:00-01:00”代表UTC时间0点开始执行备份。只能是整点时间段,间隔时间限定为一个小时。由自动切换为手动时,保留自动备份策略信息。

取值范围

不涉及。

表10 RenameCommandResp

参数

参数类型

描述

command

String

参数解释

可命令重命名的命令command。

取值范围

不涉及。

flushall

String

参数解释

可命令重命名的命令flushall。

取值范围

不涉及。

flushdb

String

参数解释

可命令重命名的命令flushdb。

取值范围

不涉及。

hgetall

String

参数解释

可命令重命名的命令hgetall。

取值范围

不涉及。

keys

String

参数解释

可命令重命名的命令keys。

取值范围

不涉及。

状态码:400

表11 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码:401

表12 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码:403

表13 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码:404

表14 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

状态码:500

表15 响应Body参数

参数

参数类型

描述

error_msg

String

参数解释

错误信息。

取值范围

不涉及。

error_code

String

参数解释

错误码。

取值范围

请参见错误码

error_ext_msg

String

参数解释

扩展错误信息(暂未使用,赋值为null)。

取值范围

不涉及。

请求示例

  • GET https://{dcs_endpoint}/v2/{project_id}/instances?offset=0&limit=10&name={name}&status={status}&id={id}&include_failure=true&include_delete=true&name_equal=false
  • 查询回收站实例。

    GET https://{dcs_endpoint}/v2/{project_id}/instances?is_recycle=true

响应示例

状态码:200

查询所有实例列表成功。

{
  "instance_num" : 1,
  "instances" : [ {
    "publicip_id" : { },
    "vpc_name" : "dcs-beta",
    "charging_mode" : 0,
    "vpc_id" : "5e37b3be-950a-48e1-b498-65b63d336481",
    "subnet_id" : "a4112635-3ec0-471c-95c3-5cf49b9533af",
    "user_name" : "clouduser",
    "created_at" : "2022-08-29T09:00:34.335Z",
    "updated_at" : "2022-08-29T09:00:34.335Z",
    "enable_ssl" : false,
    "max_memory" : 128,
    "publicip_address" : null,
    "capacity" : 0,
    "order_id" : null,
    "maintain_begin" : "18:00:00",
    "engine" : "Redis",
    "maintain_end" : "19:00:00",
    "capacity_minor" : ".125",
    "service_upgrade" : false,
    "no_password_access" : true,
    "service_task_id" : "",
    "ip" : "192.168.0.195",
    "used_memory" : 2,
    "access_user" : null,
    "instance_id" : "c830053e-d5a3-4bc0-b6d6-ca37d1ea9dd5",
    "enable_publicip" : false,
    "port" : 6379,
    "user_id" : "d53977d1adfb49c5b025ba7d33a13fd7",
    "domain_name" : "redis-c830053e-d5a3-4bc0-b6d6-ca37d1ea9dd5.dcs.**cloud.com",
    "name" : "dcs-lpvo0829",
    "spec_code" : "redis.ha.xu1.tiny.r2.128",
    "engine_version" : "5.0",
    "status" : "RUNNING",
    "security_group_id" : "securityGroupId",
    "enterprise_project_id" : 0,
    "tags" : [ {
      "key" : 1,
      "value" : "DCS"
    } ],
    "az_codes" : [ "region01", "region02" ],
    "description" : "实例描述备注",
    "cpu_type" : "x86_64",
    "features" : {
      "support_acl" : true,
      "support_transparent_client_ip" : true,
      "support_ssl" : false,
      "support_audit_log" : false
    },
    "sub_status" : "normal"
  } ]
}

状态码:400

非法请求。

{
  "error_code" : "DCS.4800",
  "error_msg" : "Invalid offset in the request."
}

SDK代码示例

SDK代码示例如下。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dcs.v2.region.DcsRegion;
import com.huaweicloud.sdk.dcs.v2.*;
import com.huaweicloud.sdk.dcs.v2.model.*;


public class ListInstancesSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DcsClient client = DcsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DcsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListInstancesRequest request = new ListInstancesRequest();
        try {
            ListInstancesResponse response = client.listInstances(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdcs.v2.region.dcs_region import DcsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdcs.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DcsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DcsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListInstancesRequest()
        response = client.list_instances(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dcs "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dcs/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := dcs.NewDcsClient(
        dcs.DcsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListInstancesRequest{}
	response, err := client.ListInstances(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查询所有实例列表成功。

400

非法请求。

401

认证信息非法。

403

请求被拒绝访问。

404

所请求的资源不存在。

500

内部服务错误。

错误码

请参见错误码