Redis cache

Learn how to use a Redis cache in your application

Overview

The redislabs.com/Redis is a resource which can be deployed to any platform Radius supports.

Resource format


resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
  name: 'redis'
  properties: {
    environment: environment
    application:app.id
    recipe: {
      // Name a specific Recipe to use
      name: 'azure-redis'
      // Set optional/required parameters (specific to the Recipe)
      parameters: {
        size: 'large'
      }
    }
  }
}

resource redis 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
  name: 'redis'
  properties: {
    environment: environment
    application:app.id
    resourceProvisioning: 'manual'
    resources: [{
      id: azureRedis.id
    }]
    username: 'myusername'
    host: azureRedis.properties.hostName
    port: azureRedis.properties.port
    secrets: {
      password: azureRedis.listKeys().primaryKey
    }
  }
}

Top-level

KeyRequiredDescriptionExample
nameyThe name of your resource.cache
locationyThe location of your resource. See common values for more information.global
propertiesyProperties of the resource.See below

Properties

PropertyRequiredDescriptionExample(s)
applicationnThe ID of the application resource this resource belongs to.app.id
environmentyThe ID of the environment resource this resource belongs to.env.id
hostnThe Redis host name.redis.hello.com
portnThe Redis port value.6379
resourceProvisioningnSpecifies how the underlying service/resource is provisioned and managed. Options are to provision automatically via ‘recipe’ or provision manually via ‘manual’. Selection determines which set of fields to additionally require. Defaults to ‘recipe’.manual
recipenConfiguration for the Recipe which will deploy the backing infrastructure.See below
resourcesnAn array of IDs of the underlying resources.See below
usernamenThe username for Redis cache.myusername
secretsnSecrets used when building the resource from values.See below
tlsnIndicates if the Redis cache is configured with SSL connections. If the port value is set to 6380 this defaults to true. Otherwise it is defaulted to false. If your Redis cache offers SSL connections on ports other than 6380, explicitly set this value to true to override the default behavior.true

Recipe

PropertyRequiredDescriptionExample(s)
<recipe-name>yThe name of the Recipe. Must be unique within the resource-type.myrecipe
parametersnA list of parameters to set on the Recipe for every Recipe usage and deployment. Can be overridden by the resource calling the Recipe.capacity: 1

Resources

PropertyRequiredDescriptionExample(s)
idnResource ID of the supporting resource.redisCache.id

Secrets

PropertyRequiredDescriptionExample(s)
connectionStringnThe connection string for the Redis cache. Write only.contoso5.redis.cache.windows.net,ssl=true,password=...
passwordnThe password for the Redis cache. Write only.mypassword
urlnThe connection URL for the Redis cache. Set automatically based on the values provided for host, port, username, and password. Can be explicitly set to override default behavior. Write only.redis://username:password@localhost:6380/0?ssl=true

Methods

The following methods are available on the Redis cache:

MethodDescriptionExample
listSecrets()Get the secrets for the Redis cache.listSecrets().connectionString

Resource provisioning

Provision with a Recipe

Recipes automate infrastructure provisioning using approved templates. When no Recipe configuration is set, Radius will use the currently registered Recipe as the default in the environment for the given resource. Otherwise, a Recipe name and parameters can optionally be set to override this default.

Provision manually

If you want to manually manage your infrastructure provisioning without the use of Recipes, you can set resourceProvisioning to 'manual' and provide all necessary parameters and values that enable Radius to deploy or connect to the desired infrastructure.

Environment variables for connections

Other Radius resources, such as containers, may connect to a Redis resource via connections. When a connection to Redis named, for example, myconnection is declared, Radius injects values into environment variables that are then used to access the connected Redis resource:

Environment variableExample(s)
CONNECTION_MYCONNECTION_HOSTmycache.redis.cache.windows.net
CONNECTION_MYCONNECTION_PORT6379
CONNECTION_MYCONNECTION_TLStrue
CONNECTION_MYCONNECTION_USERNAMEadmin
CONNECTION_MYCONNECTION_CONNECTIONSTRINGcontoso5.redis.cache.windows.net,ssl=true,password=...
CONNECTION_MYCONNECTION_PASSWORDmypassword
CONNECTION_MYCONNECTION_URLrediss://username:password@localhost:6380/0