CloudWiki
Resource

Cache for Redis

Microsoft Azure
Databases
Azure Cache for Redis is a fully-managed, in-memory data store that supports caching and data storage scenarios. It is based on the popular open-source Redis database and is designed to provide fast and scalable access to data, with low-latency and high-throughput performance. Azure Cache for Redis is a distributed cache service that can be used to store and access data in memory, reducing the need for costly database queries or expensive disk-based storage. It supports various data structures, such as strings, hashes, sets, sorted sets, and lists, and provides features such as expiration, eviction, transactions, and Lua scripting. Azure Cache for Redis can be used in a wide range of scenarios, such as session management, gaming, e-commerce, media streaming, and IoT, among others. It can also be integrated with other Azure services, such as Azure Functions, Azure Web Apps, and Azure Virtual Machines, and supports multiple clients and protocols, including Redis clients, .NET libraries, and REST APIs.‍
Terraform Name
terraform
azurerm_redis_cache
Cache for Redis
attributes:

The following arguments are supported:

  • name - (Required) The name of the Redis instance. Changing this forces a new resource to be created.
  • location - (Required) The location of the resource group. Changing this forces a new resource to be created.
  • resource_group_name - (Required) The name of the resource group in which to create the Redis instance. Changing this forces a new resource to be created.
  • capacity - (Required) The size of the Redis cache to deploy. Valid values for a SKU family of C (Basic/Standard) are 0, 1, 2, 3, 4, 5, 6, and for P (Premium) family are 1, 2, 3, 4, 5.
  • family - (Required) The SKU family/pricing group to use. Valid values are C (for Basic/Standard SKU family) and P (for Premium)
  • sku_name - (Required) The SKU of Redis to use. Possible values are Basic, Standard and Premium.

Note

Downgrading the SKU will force a new resource to be created.

  • enable_non_ssl_port - (Optional) Enable the non-SSL port (6379) - disabled by default.
  • identity - (Optional) An identity block as defined below.
  • minimum_tls_version - (Optional) The minimum TLS version. Possible values are 1.0, 1.1 and 1.2. Defaults to 1.0.
  • patch_schedule - (Optional) A list of patch_schedule blocks as defined below.
  • private_static_ip_address - (Optional) The Static IP Address to assign to the Redis Cache when hosted inside the Virtual Network. This argument implies the use of subnet_id. Changing this forces a new resource to be created.
  • public_network_access_enabled - (Optional) Whether or not public network access is allowed for this Redis Cache. true means this resource could be accessed by both public and private endpoint. false means only private endpoint access is allowed. Defaults to true.
  • redis_configuration - (Optional) A redis_configuration as defined below - with some limitations by SKU - defaults/details are shown below.
  • replicas_per_master - (Optional) Amount of replicas to create per master for this Redis Cache.

Note:

Configuring the number of replicas per master is only available when using the Premium SKU and cannot be used in conjunction with shards.

  • replicas_per_primary - (Optional) Amount of replicas to create per primary for this Redis Cache. If both replicas_per_primary and replicas_per_master are set, they need to be equal.
  • redis_version - (Optional) Redis version. Only major version needed. Valid values: 4, 6.
  • tenant_settings - (Optional) A mapping of tenant settings to assign to the resource.
  • shard_count - (Optional) Only available when using the Premium SKU The number of Shards to create on the Redis Cluster.
  • subnet_id - (Optional) Only available when using the Premium SKU The ID of the Subnet within which the Redis Cache should be deployed. This Subnet must only contain Azure Cache for Redis instances without any other type of resources. Changing this forces a new resource to be created.
  • tags - (Optional) A mapping of tags to assign to the resource.
  • zones - (Optional) Specifies a list of Availability Zones in which this Redis Cache should be located. Changing this forces a new Redis Cache to be created.

Please Note

: Availability Zones are in Preview and only supported in several regions at this time - as such you must be opted into the Preview to use this functionality. You can opt into the Availability Zones Preview in the Azure Portal.

An identity block supports the following:

  • type - (Required) Specifies the type of Managed Service Identity that should be configured on this Redis Cluster. Possible values are SystemAssigned, UserAssigned, SystemAssigned, UserAssigned (to enable both).
  • identity_ids - (Optional) A list of User Assigned Managed Identity IDs to be assigned to this Redis Cluster.

NOTE:

This is required when type is set to UserAssigned or SystemAssigned, UserAssigned.

A redis_configuration block supports the following:

  • aof_backup_enabled - (Optional) Enable or disable AOF persistence for this Redis Cache. Defaults to false.
  • aof_storage_connection_string_0 - (Optional) First Storage Account connection string for AOF persistence.
  • aof_storage_connection_string_1 - (Optional) Second Storage Account connection string for AOF persistence.

Example usage:

redis_configuration {
aof_backup_enabled = true
aof_storage_connection_string_0 = "DefaultEndpointsProtocol=https;
BlobEndpoint=${azurerm_storage_account.nc-cruks-storage-account.primary_blob_endpoint};
AccountName=${azurerm_storage_account.mystorageaccount.name};
AccountKey=${azurerm_storage_account.mystorageaccount.primary_access_key}"
aof_storage_connection_string_1 = "DefaultEndpointsProtocol=https;
BlobEndpoint=${azurerm_storage_account.mystorageaccount.primary_blob_endpoint};
AccountName=${azurerm_storage_account.mystorageaccount.name};
AccountKey=${azurerm_storage_account.mystorageaccount.secondary_access_key}"}

  • enable_authentication - (Optional) If set to false, the Redis instance will be accessible without authentication. Defaults to true.

NOTE:

enable_authentication can only be set to false if a subnet_id is specified; and only works if there aren't existing instances within
the subnet with enable_authentication set to true.

  • maxmemory_reserved - (Optional) Value in megabytes reserved for non-cache usage e.g. failover. Defaults are shown below.
  • maxmemory_delta - (Optional) The max-memory delta for this Redis instance. Defaults are shown below.
  • maxmemory_policy - (Optional) How Redis will select what to remove when maxmemory is reached. Defaults are shown below. Defaults to volatile-lru.
  • maxfragmentationmemory_reserved - (Optional) Value in megabytes reserved to accommodate for memory fragmentation. Defaults are shown below.
  • rdb_backup_enabled - (Optional) Is Backup Enabled? Only supported on Premium SKUs. Defaults to false.

NOTE:

If rdb_backup_enabled set to true, rdb_storage_connection_string must also be set.

  • rdb_backup_frequency - (Optional) The Backup Frequency in Minutes. Only supported on Premium SKUs. Possible values are: 15, 30, 60, 360, 720 and 1440.
  • rdb_backup_max_snapshot_count - (Optional) The maximum number of snapshots to create as a backup. Only supported for Premium SKUs.
  • rdb_storage_connection_string - (Optional) The Connection String to the Storage Account. Only supported for Premium SKUs. In the format: DefaultEndpointsProtocol=https;BlobEndpoint=${azurerm_storage_account.example.primary_blob_endpoint};
    AccountName=${azurerm_storage_account.example.name};
    AccountKey=${azurerm_storage_account.example.primary_access_key}
    .

NOTE:

There's a bug in the Redis API where the original storage connection string isn't being returned, which is being tracked in this issue. In the interim you can use the ignore_changes attribute to ignore changes to this field e.g.:

resource "azurerm_redis_cache" "example" {
 # ...
 ignore_changes = [redis_configuration.0.rdb_storage_connection_string]
}

  • notify_keyspace_events - (Optional) Keyspace notifications allows clients to subscribe to Pub/Sub channels in order to receive events affecting the Redis data set in some way. Reference

redis_configuration {
 maxmemory_reserved = 10
 maxmemory_delta    = 2
 maxmemory_policy   = "allkeys-lru"
}

Default Redis Configuration Values

Redis ValueBasicStandardPremiumenable_authenticationtruetruetruemaxmemory_reserved250200maxfragmentationmemory_
reserved250200maxmemory_delta250200maxmemory_policyvolatile-lruvolatile-lruvolatile-lru

NOTE:

The maxmemory_reserved, maxmemory_delta and maxfragmentationmemory_reserved settings are only available for Standard and Premium caches.
More details are available in the Relevant Links section below.

A patch_schedule block supports the following:

  • day_of_week - (Required) the Weekday name - possible values include Monday, Tuesday, Wednesday etc.
  • start_hour_utc - (Optional) the Start Hour for maintenance in UTC - possible values range from 0 - 23.

Note:

The Patch Window lasts for 5 hours from the start_hour_utc.

  • maintenance_window - (Optional) The ISO 8601 timespan which specifies the amount of time the Redis Cache can be updated. Defaults to PT5H.

Associating resources with a
Cache for Redis
Resources do not "belong" to a
Cache for Redis
Rather, one or more Security Groups are associated to a resource.
Create
Cache for Redis
via Terraform:
The following HCL provisions a Standard Redis Cache
Syntax:

resource "azurerm_resource_group" "example" {
 name     = "example-resources"
 location = "West Europe"
}

# NOTE: the Name used for Redis needs to be globally unique
resource "azurerm_redis_cache" "example" {
 name                = "example-cache"
 location            = azurerm_resource_group.example.location
 resource_group_name = azurerm_resource_group.example.name
 capacity            = 2
 family              = "C"
 sku_name            = "Standard"
 enable_non_ssl_port = false
 minimum_tls_version = "1.2"

 redis_configuration {
 }
}

Create
Cache for Redis
via CLI:
Parameters:

az redis create --location
               --name
               --resource-group
               --sku {Basic, Premium, Standard}
               --vm-size {c0, c1, c2, c3, c4, c5, c6, p1, p2, p3, p4, p5}
               [--enable-non-ssl-port]
               [--mi-system-assigned]
               [--mi-user-assigned]
               [--minimum-tls-version {1.0, 1.1, 1.2}]
               [--redis-configuration]
               [--redis-version]
               [--replicas-per-master]
               [--shard-count]
               [--static-ip]
               [--subnet-id]
               [--tags]
               [--tenant-settings]
               [--zones {1, 2, 3}]

Example:

az redis create --location westus2 --name MyRedisCache --resource-group MyResourceGroup --sku Basic --vm-size c0

aws cost
Costs
Direct Cost
Indirect Cost
No items found.
Best Practices for
Cache for Redis

Categorized by Availability, Security & Compliance and Cost

Low
Access allowed from VPN
No items found.
Low
Auto Scaling Group not in use
No items found.
Medium
Connections towards DynamoDB should be via VPC endpoints
No items found.
Medium
Container in CrashLoopBackOff state
No items found.
Low
EC2 with GPU capabilities
No items found.
Medium
EC2 with high privileged policies
No items found.
Medium
ECS cluster delete alarm
No items found.
Critical
ECS task with Admin access (*:*)
Medium
ECS task with high privileged policies
No items found.
Critical
EKS cluster delete alarm
No items found.
Medium
ElastiCache cluster delete alarm
No items found.
Medium
Ensure Container liveness probe is configured
No items found.
Medium
Ensure ECS task definition has memory limit
No items found.
Critical
Ensure EMR cluster master nodes are not publicly accessible
No items found.
More from
Microsoft Azure