Configure Azure Cache for Redis

This guide covers various configuration aspects for Azure Cache for Redis, helping you optimize performance, security, and manageability.

Introduction

Azure Cache for Redis is a fully managed, open-source Redis-compatible caching service that enables applications to access data at high throughput and low latency. Proper configuration is key to leveraging its full potential.

Prerequisites

  • An Azure subscription.
  • An existing Azure Cache for Redis instance. If you don't have one, you can create it through the Azure portal.

Configure Access

Controlling access to your Redis cache is crucial for security. You can manage access using access keys and Azure Active Directory (Azure AD) authentication.

Access Keys

Access keys are the primary method for authenticating with your Redis cache. You can regenerate these keys in the Azure portal.

1

Navigate to your Azure Cache for Redis instance in the Azure portal.

In the left menu, select Access keys.

2

View and copy the Primary and Secondary keys.

You can also regenerate keys if necessary.

Azure Active Directory (Azure AD) Authentication

For enhanced security and integration with Azure AD, you can configure authentication using Azure AD credentials.

  1. Enable Managed Identity for your Azure Cache for Redis instance.
  2. Grant the managed identity appropriate roles (e.g., "Redis Reader" or "Redis Contributor") on other Azure resources if needed.
  3. Configure your application to use Azure AD authentication with Redis.

Tip: Using Azure AD authentication is recommended for production environments for better security and access management.

Configure Clustering

Clustering allows you to shard your data across multiple Redis nodes, increasing the overall throughput and memory capacity of your cache.

Important: Clustering can only be enabled when the cache is created. It cannot be enabled on an existing non-clustered cache.

To configure clustering for a new cache:

  1. When creating a new Azure Cache for Redis instance, select the Premium tier.
  2. Under the Advanced features tab, enable Clustering.
  3. Specify the number of shards (nodes) for your cluster.

For existing clustered caches, you can adjust the number of shards (up to the maximum supported by the tier) through the Azure portal.

Configure Persistence

Persistence allows you to save your Redis data to a disk, enabling data recovery in case of cache restarts or failures. Azure Cache for Redis supports RDB and AOF persistence.

RDB Persistence

RDB (Redis Database) persistence saves a point-in-time snapshot of your dataset to a file.

  1. Navigate to your Azure Cache for Redis instance in the Azure portal.
  2. In the left menu, select Persistence.
  3. Choose RDB persistence.
  4. Configure the backup frequency and choose a storage account.

AOF Persistence

AOF (Append Only File) persistence logs every write operation received by the server. This provides better durability than RDB.

  1. Navigate to your Azure Cache for Redis instance in the Azure portal.
  2. In the left menu, select Persistence.
  3. Choose AOF persistence.
  4. Configure the AOF data sync frequency.

Note: Persistence is only available for Premium tier caches.

Configure SSL/TLS

Enabling SSL/TLS encrypts data in transit between your clients and the Redis server, ensuring secure communication.

By default, Azure Cache for Redis allows non-SSL connections on port 6379 and SSL connections on port 6380. For enhanced security, it's recommended to disable non-SSL port access.

  1. Navigate to your Azure Cache for Redis instance in the Azure portal.
  2. In the left menu, select Advanced settings.
  3. Toggle Non-SSL port to Off.

Ensure your client applications are configured to use SSL/TLS connections. The SSL port remains 6380.

Configure Firewall

The firewall rules allow you to restrict network access to your Redis cache, enabling connections only from specified IP addresses or ranges.

  1. Navigate to your Azure Cache for Redis instance in the Azure portal.
  2. In the left menu, select Firewall.
  3. Configure Allow access from to Selected.
  4. Add new rules with Start IP address and End IP address to define your allowed IP ranges.

Tip: For robust security, consider integrating Azure Cache for Redis with Azure Virtual Network (VNet) service endpoints or private endpoints.

Monitoring

Regular monitoring of your Azure Cache for Redis instance is essential for identifying performance bottlenecks, detecting potential issues, and ensuring optimal operation.

Key metrics to monitor include:

  • Cache Hits/Misses
  • Operations per Second
  • Memory Usage
  • CPU Usage
  • Network In/Out
  • Connected Clients

Azure Monitor provides comprehensive tools for setting up alerts, dashboards, and analyzing performance data for your Redis cache.