[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Valkey™](../index.md) > [Step-by-step guides](index.md) > Clusters > Valkey™ version update

# Valkey™ version upgrade

You can upgrade a Yandex Managed Service for Valkey™ cluster to any supported version.


## Supported versions {#version-supported}

All Valkey™ versions supported in Yandex Managed Service for Valkey™ remain available as long as they are supported by the vendor. Typically, this is 24 months from the version release date. For more information, see [this Valkey™ guide](https://valkey.io/topics/releases/).


### Viewing a list of available Valkey™ versions {#version-list}

{% list tabs group=instructions %}

- Management console {#console}

    1. Navigate to **Yandex Managed Service for&nbsp;Valkey™**.
    1. Select the cluster and click **Edit**.
    1. Open the list in the **Version** field.

    {% note info %}

    To specify a version number in the CLI, Terraform, and the API, add the `-valkey` suffix to it, e.g., `8.1-valkey`.

    {% endnote %}

{% endlist %}

## Before upgrading a version {#before-update}

Make sure the upgrade will not disrupt your applications:

1. Check the Valkey™ [release notes](https://docs.redis.com/latest/rs/release-notes/) to learn how upgrades may affect your applications.
1. Try upgrading a test cluster. You can [deploy it from a backup](cluster-backups.md#restore) of the main cluster, if Yandex Managed Service for Valkey™ [supports](#version-supported) the Valkey™ version in the backup.
1. [Back up](cluster-backups.md#create-backup) your main cluster before upgrading.

## Upgrading a cluster {#start-update}

{% note alert %}

* After the DBMS upgrade, you cannot revert the cluster to the previous version.
* Whether a Valkey™ version upgrade succeeds depends on multiple factors, including your cluster’s configuration and the nature of the stored data. We recommend that you start with [upgrading a test cluster](#before-update) with the same data and configuration.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), go to the folder containing the cluster to upgrade.
  1. Navigate to **Yandex Managed Service for&nbsp;Valkey™**.
  1. Select the cluster you need from the list and click **Edit**.
  1. In the **Version** field, select the new version.
  1. Click **Save changes**.

  As soon as you run the upgrade, the cluster status will change to **Updating**. Wait for the operation to complete and then check the cluster version.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. Get the list of your Valkey™ clusters using this command:

     ```bash
     yc managed-redis cluster list
     ```

  1. Get information about the cluster in question and check its Valkey™ version in the `config.version` setting:

     ```bash
     yc managed-redis cluster get <cluster_name_or_ID>
     ```

  1. Start the Valkey™ upgrade:

     ```bash
     yc managed-redis cluster update <cluster_name_or_ID> \
       --redis-version <new_version_number>
     ```

     As soon as you run the upgrade, the cluster status will change to **Updating**. Wait for the operation to complete and then check the cluster version.

- Terraform {#tf}

    1. Open the current Terraform configuration file with the infrastructure plan.

        For information on how to create this file, see [Creating a cluster](cluster-create.md).

    1. Update the `version` argument in the `config` section to specify the Valkey™ version you want to upgrade to:

        ```hcl
        resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
          ...
          config = {
            version  = "<new_version_number>"
            ...
          }
        }
        ```

    1. Make sure the settings are correct.

        1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
        1. Run this command:
        
           ```bash
           terraform validate
           ```
        
           Terraform will show any errors found in your configuration files.

    1. Confirm updating the resources.

        1. Run this command to view the planned changes:
        
           ```bash
           terraform plan
           ```
        
           If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
        
        1. If everything looks correct, apply the changes:
           1. Run this command:
        
              ```bash
              terraform apply
              ```
        
           1. Confirm updating the resources.
           1. Wait for the operation to complete.

    For more information, see [this Terraform provider guide](../../terraform/resources/mdb_redis_cluster_v2.md).

    {% note warning "Timeouts" %}
    
    The Terraform provider sets the following timeouts for Yandex Managed Service for Valkey™ cluster operations:
    
    * Creating a cluster, including by restoring it from a backup: 15 minutes.
    * Editing a cluster: 60 minutes.
    * Deleting a cluster: 15 minutes.
    
    Operations exceeding the timeout are aborted.
    
    {% cut "How do I change these limits?" %}
    
    Add the `timeouts` section to your cluster description, such as the following:
    
    ```hcl
    resource "yandex_mdb_redis_cluster_v2" "<cluster_name>" {
      ...
      timeouts = {
        create = "1h30m" # 1 hour 30 minutes
        update = "2h"    # 2 hours
        delete = "30m"   # 30 minutes
      }
    }
    ```
    
    {% endcut %}
    
    {% endnote %}

- REST API {#api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Call the [Cluster.Update](../api-ref/Cluster/update.md) method, e.g., via the following [cURL](https://curl.se/) request:

        {% note warning %}
        
        The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `updateMask` parameter as a single comma-separated string.
        
        {% endnote %}

        ```bash
        curl \
            --request PATCH \
            --header "Authorization: Bearer $IAM_TOKEN" \
            --header "Content-Type: application/json" \
            --url 'https://mdb.api.cloud.yandex.net/managed-redis/v1/clusters/<cluster_ID>' \
            --data '{
                      "updateMask": "configSpec.version",
                      "configSpec": {
                        "version": "<Valkey™_version>"
                      }
                    }'
        ```

        Where:

        * `updateMask`: Comma-separated string of settings to update.

            Here, we provide only one setting.

        * `configSpec.version`: New Valkey™ version.

        You can request the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/Cluster/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

- gRPC API {#grpc-api}

    1. [Get an IAM token for API authentication](../api-ref/authentication.md) and put it into an environment variable:

        ```bash
        export IAM_TOKEN="<IAM_token>"
        ```

    1. Clone the [cloudapi](https://github.com/yandex-cloud/cloudapi) repository:
       
       ```bash
       cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
       ```
       
       Below, we assume that the repository contents reside in the `~/cloudapi/` directory.

    1. Call the [ClusterService.Update](../api-ref/grpc/Cluster/update.md) method, e.g., via the following [gRPCurl](https://github.com/fullstorydev/grpcurl) request:

        {% note warning %}
        
        The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the `update_mask` parameter as an array of `paths[]` strings.
        
        {% cut "Format for listing settings" %}
        
        ```yaml
        "update_mask": {
            "paths": [
                "<setting_1>",
                "<setting_2>",
                ...
                "<setting_N>"
            ]
        }
        ```
        
        {% endcut %}
        
        {% endnote %}

        ```bash
        grpcurl \
            -format json \
            -import-path ~/cloudapi/ \
            -import-path ~/cloudapi/third_party/googleapis/ \
            -proto ~/cloudapi/yandex/cloud/mdb/redis/v1/cluster_service.proto \
            -rpc-header "Authorization: Bearer $IAM_TOKEN" \
            -d '{
                  "cluster_id": "<cluster_ID>",
                  "update_mask": {
                    "paths": [ "config_spec.version" ]
                  },
                  "config_spec": {
                    "version": "<Valkey™_version>"
                  } 
                }' \
            mdb.api.cloud.yandex.net:443 \
            yandex.cloud.mdb.redis.v1.ClusterService.Update
        ```

        Where:

        * `update_mask`: List of settings you want to update as an array of strings (`paths[]`).

            Here, we provide only one setting.

        * `config_spec.version`: New Valkey™ version.

        You can request the cluster ID with the [list of clusters in the folder](cluster-list.md#list-clusters).

    1. Check the [server response](../api-ref/grpc/Cluster/update.md#yandex.cloud.operation.Operation) to make sure your request was successful.

{% endlist %}

## Examples {#examples}

Let's assume you need to upgrade your cluster version from 8.1 to 9.0.

{% list tabs group=instructions %}

- CLI {#cli}

   1. To get the list of clusters with their IDs and names, run this command:

      ```bash
      yc managed-redis cluster list
      ```

	  Result:
	  
      ```text
      +----------------------+---------------+---------------------+--------+---------+
      |          ID          |     NAME      |     CREATED AT      | HEALTH | STATUS  |
      +----------------------+---------------+---------------------+--------+---------+
      | c9q8p8j2gaih******** |   redis406    | 2022-04-23 12:44:17 | ALIVE  | RUNNING |
      +----------------------+---------------+---------------------+--------+---------+
      ```

   1. To get information about the `redis406` cluster, run the following command:

      ```bash
      yc managed-redis cluster get redis406
      ```

      Result:

      ```text
      id: c9q8p8j2gaih********
      ...
      config:
        version: 8.1-valkey
        ...
      ```

   1. To upgrade a cluster named `redis406` to version `9.0`, run the following command:

      ```bash
      yc managed-redis cluster update redis406 --redis-version 9.0-valkey`
      ```

{% endlist %}