

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用全域資料存放區 (CLI)
<a name="Redis-Global-Datastores-CLI"></a>

您可以使用 AWS Command Line Interface (AWS CLI) 從命令列控制多個 AWS 服務，並透過指令碼將其自動化。您可以使用 AWS CLI 進行臨機操作 （一次性）。

## 下載和設定 AWS CLI
<a name="Redis-Global-Datastores-Downloading-CLI"></a>

 AWS CLI 會在 Windows、macOS 或 Linux 上執行。請使用下列程序來下載並進行設定。

**下載、安裝及設定 CLI**

1. 在[AWS 命令列界面](https://aws.amazon.com/cli)網頁上下載 AWS CLI。

1. 遵循*AWS Command Line Interface 《 使用者指南*》中安裝 AWS CLI 和設定 AWS CLI 的指示。

## 將 AWS CLI 與全域資料存放區搭配使用
<a name="Redis-Global-Datastores-Using-CLI"></a>

使用下列 CLI 作業來處理全域資料存放區：
+ [create-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-global-replication-group.html)

  ```
  aws elasticache create-global-replication-group \
     --global-replication-group-id-suffix {{my global datastore }} \
     --primary-replication-group-id {{sample-repl-group }} \
     --global-replication-group-description {{an optional description of the global datastore }}
  ```

  建立時，Amazon ElastiCache 會自動將字首套用至全域資料存放區 ID。每個 AWS 區域都有自己的字首。例如，在美國西部 (加利佛尼亞北部) 區域建立的全域資料儲存 ID 都以 "virxk" 開頭，加上您提供的尾碼名稱。尾碼與自動產生的字首結合，可保證跨多個區域的全域資料存放區名稱保持唯一性。

  下表列出每個 AWS 區域及其全域資料存放區 ID 字首。

    
****    
[See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/AmazonElastiCache/latest/dg/Redis-Global-Datastores-CLI.html)
+  [create-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-replication-group.html) - 使用此作業可透過將全域資料存放區的名稱提供給 `--global-replication-group-id` 參數，為全域資料存放區建立次要叢集。

  ```
  aws elasticache create-replication-group \
    --replication-group-id {{secondary replication group name}} \
    --replication-group-description {{“Replication group description"}} \
    --global-replication-group-id {{global datastore name}}
  ```

  呼叫此操作並傳入`--global-replication-group-id`值時，ElastiCache 會從全域複寫群組的主要複寫群組推斷下列參數的值。請勿傳入這些參數的值：

  `"PrimaryClusterId",`

  `"AutomaticFailoverEnabled",`

  ` "NumNodeGroups",`

  ` "CacheParameterGroupName",`

  ` "CacheNodeType",`

  ` "Engine",`

  ` "EngineVersion",`

  ` "CacheSecurityGroupNames",`

  ` "EnableTransitEncryption",`

  ` "AtRestEncryptionEnabled",`

  ` "SnapshotArns",`

  ` "SnapshotName"`
+ [describe-global-replication-groups](https://docs.aws.amazon.com/cli/latest/reference/elasticache/describe-global-replication-groups.html)

  ```
  aws elasticache describe-global-replication-groups \
     --global-replication-group-id {{my global datastore }} \
     --show-member-info {{an optional parameter that returns a list of the primary and secondary clusters that make up the global datastore }}
  ```
+ [modify-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/modify-global-replication-group.html)

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --automatic-failover-enabled \
     --cache-node-type {{node type}} \
     --cache-parameter-group-name {{parameter group name}} \ 
     --engine-version {{engine version}} \
     -—apply-immediately \
     --global-replication-group-description {{description}}
  ```

  **ElastiCache GlobalDataStore 的 Redis 至 OSS Valkey 跨引擎升級**

  您可以使用主控台、API 或 CLI，將現有的 Redis OSS 全域複寫群組升級至 Valkey。

  如果您有現有的 Redis OSS 全域複寫群組，您可以使用 modify-global-replication-group API 指定新的引擎和引擎版本，以升級至 Valkey。

  針對 Linux、macOS 或 Unix：

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --apply-immediately \
     --engine-version 8.0
  ```

  針對 Windows：

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --apply-immediately ^
     --engine-version 8.0
  ```

  如果您將自訂快取參數群組套用至想要升級的現有 Redis OSS 全域複寫群組，您也需要在請求中傳遞自訂的 Valkey 快取參數群組。輸入 Valkey 自訂參數群組必須與現有的 Redis OSS 自訂參數群組具有相同的 Redis OSS 靜態參數值。

  針對 Linux、macOS 或 Unix：

  ```
  aws elasticache modify-global-replication-group \
     --global-replication-group-id myGlobalReplGroup \
     --engine valkey \
     --engine-version 8.0 \
     --apply-immediately \
     --cache-parameter-group-name myParamGroup
  ```

  針對 Windows：

  ```
  aws elasticache modify-global-replication-group ^
     --global-replication-group-id myGlobalReplGroup ^
     --engine valkey ^
     --engine-version 8.0 ^
     --apply-immediately ^
     --cache-parameter-group-name myParamGroup
  ```
+ [delete-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/delete-global-replication-group.html)

  ```
  aws elasticache delete-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --retain-primary-replication-group {{defaults to true }}
  ```
+ [disassociate-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/disassociate-global-replication-group.html)

  ```
  aws elasticache disassociate-global-replication-group \
     --global-replication-group-id {{my global datastore }} \
     --replication-group-id {{my secondary cluster }} \
     --replication-group-region {{the AWS Region in which the secondary cluster resides}}
  ```
+ [failover-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/failover-global-replication-group.html)

  ```
  aws elasticache failover-replication-group \
     --global-replication-group-id {{my global datastore }}\
     --primary-region {{The AWS Region of the primary cluster }}\  
     --primary-replication-group-id  {{The name of the global datastore, including the suffix.}}
  ```
+ [increase-node-groups-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/increase-node-groups-in-global-replication-group.html)

  ```
  aws elasticache increase-node-groups-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}} \
     --node-group-count {{3}}
  ```
+ [decrease-node-groups-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/decrease-node-groups-in-global-replication-group.html)

  ```
  aws elasticache decrease-node-groups-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}} \
     --node-group-count {{3}}
  ```
+ [rebalance-shards-in-global-replication-group](https://docs.aws.amazon.com/cli/latest/reference/elasticache/rebalance-slots-in-global-replication-group.html)

  ```
  aws elasticache rebalance-shards-in-global-replication-group \
     --apply-immediately {{yes}} \
     --global-replication-group-id {{global-replication-group-name}}
  ```

使用說明列出 ElastiCache for Valkey 或 Redis OSS 的所有可用命令。

```
aws elasticache help
```

您還可以使用說明來描述特定命令，並了解更多關於它的用法：

```
aws elasticache create-global-replication-group help
```