Web App Service allows you to orchestrate ApsaraDB for Redis resources. To add a Redis instance to your environment, you must configure the database type, database version, storage type, and other required settings for the instance.

Background information

ApsaraDB for Redis is a database service that is compatible with open-source Redis protocols and supports hybrid storage with a blend of memory and hard disks. With reliable dual-node hot standby and scalable clusters, Redis meets your requirements for high-performance read/write operations and flexible configuration changes.

After you enable Redis, the following methods are available for you to add an ApsaraDB for RDS instance to an environment:
  • Surrogate Purchase: If you select this option, Web App Service will automatically purchase a Redis instance on your behalf. You must first specify the billing method, version type, architecture type, number of shards, node type, instance type, and password for the instance. A pay-as-you-go billing method is for short-term use. The pay-as-you-go billing method allows you to pay only for the number of resources that you use. Compared with a pay-as-you-go billing method, a subscription billing method is more cost-effective for long-term use. The subscription billing method allows you to pay for a service based on the subscription duration. For more information about Redis pricing, see Billing types.
  • Import: If you select this option, you must create ApsaraDB for RDS instances before using Web App Service. Then, you can import an existing instance to Web App Service. If you import an existing Redis instance, you do not need to specify the billing method, version type, architecture type, number of shards, node type, and other parameters for the instance.

You can use Web App Service to purchase Redis instances on your behalf or imported Redis instances. To ensure data security, Redis instances remain unchanged even if the environment that hosts these instances is released. You can log on to the Redis console to back up data and release instances.

Precautions

  • You cannot switch between billing methods. The billing methods include pay-as-you-go and subscription.
  • You can only change the password for each subscription instance. Changes to other parameters are invalid.
  • You can change the password and instance type for each pay-as-you-go instance. Changes to other parameters are invalid.
  • When you add pay-as-you-go or subscription Redis instances of the surrogate purchase type, a default account is created for each Redis instance. You can leave the password field blank.

Redis instances of the surrogate purchase type

  1. On the Environment Details page, click ApsaraDB for Redis.
  2. On the ApsaraDB for Redis page, turn on the Enable Redis switch.
  3. Select Surrogate Purchase in the Instance Source field.
  4. Select Billing Method.
    • Pay-As-You-Go: You pay for the number of resources after you consume the resources. When you release or scale down an environment, instances that are attached to the instance will not be released. A pay-as-you-go billing method is for short-term use.
    • Subscription: You need to set a subscription duration and pay for an instance upfront based on the subscription duration. When you release or scale down an environment, instances that are attached to the environment will not be released. Compared to a pay-as-you-go billing method, a subscription billing method is more cost-effective for long-term use.
  5. Select VSwitch from the drop-down list. A VSwitch is a basic building block to create a VPC. If no VSwitch is available in a VPC, you must Create a VSwitch.
  6. Set the required parameters for a Redis instance.
    Parameter Description
    Version
    • Community: supports hybrid storage that integrates memory with hard disks and open-source Redis protocols.
    • Enterprise: The Enterprise version and the Community version complement each other in areas, such as performance, storage media, and data structure. .
    Database Edition Available database editions for Redis instances of the Enterprise version include:
    Note Database editions are not available for Redis instances of the Community version.
    Database Version Available database versions for Redis instances include:
    • 2.8
    • 4.0
    • 5.0
    Note
    • If the required database version does not appear, we recommend that you specify a different database edition or instance version.
    • Redis instances of the 2.8 database version are about to be recalled. To obtain more features and higher performance, we recommend that you create Redis instances of the latest database version.
    Architecture Type
    • Cluster
    • Standard
    • Read/Write Splitting
    For more information, see Overview.
    Shards The number of shards for a Redis instance of the Cluster architecture type.
    Node Type

    Only the Dual-copy node type is available for Standard and Cluster Redis instances. To ensure persistent data storage, Redis instances of the Dual-copy node type adopt hot standby. The architecture includes a combination of a primary node and a secondary node for real-time failover.

    Instance Type Each instance type includes a set of configurations, such as the memory size, maximum number of connections, and bandwidth limit. For more information, see Overview.
    Note After you create a Redis instance, metadata for a database is generated and uses a minimum amount of storage space.
    • On a Redis instance of the Standard architecture type, the size of metadata ranges from 30 MB to 50 MB.
    • On each shard of a Redis instance of the Cluster architecture type, the size of metadata ranges from 30 MB to 50 MB. In a cluster, the total amount of storage space that metadata uses is the total size of metadata on each shard.
  7. Enter a Password.
  8. In the upper-right corner of the page, click Edit Configuration to apply the update.

Import an SLB instance

  1. On the ApsaraDB for Redis page, turn on the Enable Redis switch.
  2. Instance SourceSelect Import.
  3. In the Redis Instance list, select an existing Redis instance.
  4. Enter a valid password for the default account of the Redis instance.
  5. In the upper-right corner of the page, click Edit Configuration to apply the update.

Use the CLI tool to configure the Redis instance

The CLI tool uses the Wpfile file to configure Redis instance. You can use the wpctl dump to retrieve the Wpfile file of a deployment environment. You can add, modify, and remove Redis-related parameters. Then, you can use the apply command to apply the update.

The resources.redis section of the Wpfile file contains Redis-related parameters. The following table describes the parameters.

Parameter Name Valid value Default value Description
enable [DO NOT TRANSLATE] true and false false Specified whether to enable Redis.
imported [DO NOT TRANSLATE] true and false false Specified whether to import an existing Redis instance.
redisId [DO NOT TRANSLATE] Valid Redis instance IDs N/A The ID of the Redis instance. If you want to import an existing Redis instance, you must specify the parameter.
engineVersion [DO NOT TRANSLATE] 2.8, 4.0, and 5.0 5.0 The database version for the Redis instance.
instanceChargeType [DO NOT TRANSLATE] PrePaid and PostPaid PostPaid The billing method for the surrogate Redis instance.
periodUnit [DO NOT TRANSLATE] Year and Month Month The unit of the subscription duration.
period [DO NOT TRANSLATE] If you specify Year for the periodUnit parameter, the valid values of the parameter include 1, 2, and 3. If you specify Month for the periodUnit parameter, the valid values of the parameter include 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, and 36. 1 The subscription duration.
password [DO NOT TRANSLATE] letters, digits, and special characters Special characters include @#$%^&*()_+-=. N/A The password for the Redis account. The password must be 8 to 32 characters in length.
instanceClass [DO NOT TRANSLATE] Valid instance types N/A The instance type of the Redis instance.
vSwitchId [DO NOT TRANSLATE] Valid VSwitch IDs N/A The ID of the VSwitch for the zone where the Redis instance resides.
zoneId [DO NOT TRANSLATE] Valid zone IDs N/A The ID of the zone where the Redis instance resides.

Attach a Redis instance to an application

After you enable Redis for an environment, Web App Service uses environment variables to pass the required information about database connection to the application that runs in the environment. The application retrieves the required information about database connection from the following environment variables:
  • WP_REDIS_CONNECTION_ADDRESS: includes the internal endpoint of a Redis instance.
  • WP_REDIS_PORT: includes a port number that is used to connect to a Redis instance.
  • WP_REDIS_ACCOUNT_NAME: includes the name of an account that is used to connect to a Redis instance.
  • WP_REDIS_ACCOUNT_PASSWORD: includes a password that corresponds to the account.
  • WP_REDIS_ENGINE_VERSION: includes the version of a Redis instance.