# Cache for Redis

Source: /azure/services/cache-for-redis/

## Introduction

Azure Cache for Redis is a managed in-memory data store based on Redis, offered in the Basic, Standard, and Premium tiers. Applications use it as a distributed cache, a session store, and a message broker. For more information, see [What is Azure Cache for Redis?](https://learn.microsoft.com/azure/azure-cache-for-redis/cache-overview)

:::note
Microsoft is retiring Azure Cache for Redis and recommends [Azure Managed Redis](/azure/services/managed-redis/) for new workloads. In the Azure public cloud, creating Basic, Standard, or Premium caches has been blocked since April 1, 2026 for tenants that had no cache before that date. For details, see the [Azure Cache for Redis retirement FAQ](https://learn.microsoft.com/azure/azure-cache-for-redis/retirement-faq).
:::

LocalStack for Azure provides a local environment for building and testing applications that use Azure Cache for Redis.
Each cache you create is backed by a real Redis server running in its own container, so your application runs its own Redis commands, with the same clients, against a real Redis engine.
The cache serves TLS on its SSL port, and optionally plaintext on its non-TLS port, authenticates clients with the cache's access keys, and enforces its firewall rules and public network access setting.

The supported APIs are listed in the [API Coverage](#api-coverage) section.

## Getting started

This guide is designed for users new to Azure Cache for Redis and assumes basic knowledge of the Azure CLI, our `lstk az` proxy, and `redis-cli`.

Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/).

If you start the emulator with the `docker` CLI or Docker Compose, publish TCP ports `4510-4559` on the same host ports and mount `/var/run/docker.sock:/var/run/docker.sock` so the emulator can start its Redis containers. The `lstk` CLI configures these settings automatically.

Once the container is running, enable Azure CLI interception by running:

```bash
lstk az start-interception
```

This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
To revert this configuration, run:

```bash
lstk az stop-interception
```

This reconfigures the `az` CLI to send commands to the official Azure management REST API.

### Create a resource group

Create a resource group to contain your cache:

```bash
az group create \
  --name rg-redis-demo \
  --location westeurope
```

```bash title="Output"
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-redis-demo",
  "location": "westeurope",
  "name": "rg-redis-demo",
  "properties": {
    "provisioningState": "Succeeded"
  },
  ...
}
```

### Create a cache

Create a Basic C0 cache that requires TLS 1.2 or later:

```bash
az redis create \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --location westeurope \
  --sku Basic \
  --vm-size c0 \
  --minimum-tls-version 1.2
```

```bash title="Output"
{
  "enableNonSslPort": false,
  "hostName": "redis-demo-cache.redis.azure.localhost.localstack.cloud",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-redis-demo/providers/Microsoft.Cache/Redis/redis-demo-cache",
  "minimumTlsVersion": "1.2",
  "name": "redis-demo-cache",
  "port": 6379,
  "provisioningState": "Succeeded",
  "publicNetworkAccess": "Enabled",
  "sku": {
    "capacity": 0,
    "family": "C",
    "name": "Basic"
  },
  "sslPort": 4510,
  ...
}
```

Show the cache's host name and ports:

```bash
az redis show \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --query "{hostName:hostName, sslPort:sslPort, enableNonSslPort:enableNonSslPort, sku:sku.name, provisioningState:provisioningState}"
```

```bash title="Output"
{
  "enableNonSslPort": false,
  "hostName": "redis-demo-cache.redis.azure.localhost.localstack.cloud",
  "provisioningState": "Succeeded",
  "sku": "Basic",
  "sslPort": 4510
}
```

The host name is an emulator host name rather than `redis-demo-cache.redis.cache.windows.net`, and the SSL port is a port the emulator assigns to the cache rather than 6380.

### Connect to the cache

Capture the host name, the SSL port, and the primary access key. `redis-cli` reads its password from the `REDISCLI_AUTH` environment variable:

```bash
export REDIS_HOST=$(az redis show --name redis-demo-cache --resource-group rg-redis-demo --query hostName --output tsv)
export REDIS_PORT=$(az redis show --name redis-demo-cache --resource-group rg-redis-demo --query sslPort --output tsv)
export REDISCLI_AUTH=$(az redis list-keys --name redis-demo-cache --resource-group rg-redis-demo --query primaryKey --output tsv)
```

Connect over TLS, then write and read a key:

```bash
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PING
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls SET greeting "Hello from LocalStack"
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls GET greeting
```

```bash title="Output"
PONG
OK
Hello from LocalStack
```

The cache presents the LocalStack public certificate, whose `*.redis.azure.localhost.localstack.cloud` entry covers the host name, so `redis-cli` and other clients verify the server against the public roots they already trust, as they do against Azure.
When LocalStack cannot download that certificate, for example with `SKIP_SSL_CERT_DOWNLOAD=1` or without outbound network access, the cache presents a certificate issued by the LocalStack root certificate authority instead, and a client needs that authority, for example with `redis-cli --cacert`.

### Regenerate an access key

Regenerate the secondary key. The primary key, and the sessions authenticated with it, stay valid:

```bash
az redis regenerate-keys \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --key-type Secondary \
  --output none
```

### Use the non-TLS port

Enable the non-TLS port:

```bash
az redis update \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --set enableNonSslPort=true \
  --query "{enableNonSslPort:enableNonSslPort, port:port}"
```

```bash title="Output"
{
  "enableNonSslPort": true,
  "port": 4511
}
```

While the non-TLS port is enabled, `port` is a port the emulator assigns to the cache rather than 6379.
Capture it and connect without TLS:

```bash
export REDIS_PLAINTEXT_PORT=$(az redis show --name redis-demo-cache --resource-group rg-redis-demo --query port --output tsv)
redis-cli -h "$REDIS_HOST" -p "$REDIS_PLAINTEXT_PORT" GET greeting
```

```bash title="Output"
Hello from LocalStack
```

Disable the non-TLS port again:

```bash
az redis update \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --set enableNonSslPort=false \
  --query "{enableNonSslPort:enableNonSslPort}"
```

```bash title="Output"
{
  "enableNonSslPort": false
}
```

### Restrict access with firewall rules

Create a firewall rule that admits only the `203.0.113.0/24` documentation range:

```bash
az redis firewall-rules create \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --rule-name allow-office \
  --start-ip 203.0.113.1 \
  --end-ip 203.0.113.254
```

```bash title="Output"
{
  "endIp": "203.0.113.254",
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-redis-demo/providers/Microsoft.Cache/Redis/redis-demo-cache/firewallRules/allow-office",
  "name": "redis-demo-cache/allow-office",
  "resourceGroup": "rg-redis-demo",
  "startIp": "203.0.113.1",
  "type": "Microsoft.Cache/Redis/firewallRules"
}
```

List the firewall rules:

```bash
az redis firewall-rules list \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --query "[].{name:name, startIp:startIp, endIp:endIp}" \
  --output table
```

```bash title="Output"
Name                           StartIp      EndIp
-----------------------------  -----------  -------------
redis-demo-cache/allow-office  203.0.113.1  203.0.113.254
```

Your client's address is outside the rule, so the cache now refuses the connection:

```bash
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PING
```

```bash title="Output"
Could not connect to Redis at redis-demo-cache.redis.azure.localhost.localstack.cloud:4510: SSL_connect failed: unexpected eof while reading
```

Delete the rule to admit every address again:

```bash
az redis firewall-rules delete \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --rule-name allow-office
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PING
```

```bash title="Output"
PONG
```

### Schedule updates

Set a maintenance window for Sundays at 02:00 UTC:

```bash
az redis patch-schedule create \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --schedule-entries '[{"dayOfWeek":"Sunday","startHourUtc":2,"maintenanceWindow":"PT5H"}]'
```

```bash title="Output"
{
  "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-redis-demo/providers/Microsoft.Cache/Redis/redis-demo-cache/patchSchedules/default",
  "location": "West Europe",
  "name": "redis-demo-cache/default",
  "resourceGroup": "rg-redis-demo",
  "scheduleEntries": [
    {
      "dayOfWeek": "Sunday",
      "maintenanceWindow": "5:00:00",
      "startHourUtc": 2
    }
  ],
  "type": "Microsoft.Cache/Redis/PatchSchedules"
}
```

Show the schedule:

```bash
az redis patch-schedule show \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --query "scheduleEntries"
```

```bash title="Output"
[
  {
    "dayOfWeek": "Sunday",
    "maintenanceWindow": "5:00:00",
    "startHourUtc": 2
  }
]
```

### Reboot and flush the cache

Reboot the cache. A reboot doesn't remove its data:

```bash
az redis force-reboot \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --reboot-type AllNodes
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls DBSIZE
```

```bash title="Output"
{
  "message": "The requested reboot operation for 'Value' has been successfully scheduled and should be executed shortly."
}
1
```

Flush the cache to remove every key:

```bash
az redis flush \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --yes
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls DBSIZE
```

```bash title="Output"
{
  "status": "Succeeded",
  ...
}
0
```

### Delete the cache

Delete the cache and the resource group:

```bash
az redis delete \
  --name redis-demo-cache \
  --resource-group rg-redis-demo \
  --yes
az group delete \
  --name rg-redis-demo \
  --yes
```

## Features

- **Cache lifecycle**: Create, show, list, update, and delete caches in the Basic, Standard, and Premium tiers, and check whether a cache name is available.
- **Real Redis server**: Each cache runs a Redis server in its own container, so clients connect with the Redis protocol and run Redis commands against a real Redis engine.
- **TLS and non-TLS ports**: The cache serves TLS on its SSL port, with a certificate that covers its host name, and plaintext on its non-TLS port while `enableNonSslPort` is `true`. Enabling or disabling the non-TLS port keeps the data, the keys, and the TLS endpoint.
- **Access keys**: Clients authenticate with the primary or the secondary key. `az redis regenerate-keys` replaces only the key you name, and setting `disableAccessKeyAuthentication` turns key authentication off and closes the sessions authenticated with a key.
- **Firewall rules**: Create, show, list, and delete firewall rules. While a cache has rules, it admits only clients whose address falls in one of them, and closes existing sessions from other addresses.
- **Public network access**: Setting `publicNetworkAccess` to `Disabled` refuses new connections and closes existing ones.
- **Scaling**: Changing the SKU follows the scaling rules of Azure: a cache can't move to a lower tier, from Basic straight to Premium, change size while moving from Basic to Standard, or scale down to C0.
- **Administration**: Reboot a cache, which restarts its Redis server and keeps its data, flush a cache, and manage its update schedule.

## Limitations

- **One Redis server per cache**: A cache has no replica and no shards. Premium clustering, shard counts, replicas per primary, and availability zones are stored but not provisioned.
- **Redis 8.2 instead of Redis 6**: Every cache runs Redis 8.2, while Azure Cache for Redis runs Redis 6, so commands added in Redis 7 and later work locally but fail in Azure. The Redis modules, which Azure Cache for Redis doesn't offer, are not loaded.
- **Memory size isn't enforced**: The SKU's size sets no memory limit, so eviction never happens.
- **Redis configuration is not applied**: Settings in `redisConfiguration`, such as `maxmemory-policy` and `notify-keyspace-events`, are stored and returned but not applied to the Redis server.
- **Update schedules are metadata-only**: Patch schedules are stored and returned, and no maintenance takes place.
- **Firewall rules see the address that reaches the emulator**: When LocalStack runs in Docker, a connection from your machine reaches the cache from the gateway address of the emulator's Docker network, such as `172.17.0.1`, rather than from your machine's address, and firewall rules apply to that address.
- **Unsupported features**: Microsoft Entra authentication and access policies, geo-replication and linked servers, import and export, data persistence, virtual network injection, and Private Link are not supported.

## Samples

Explore end-to-end examples in the [LocalStack for Azure Samples](https://github.com/localstack/localstack-azure-samples) repository.

## API Coverage


### Cache for Redis API coverage

Source service: `cache-for-redis`. 21 of 34 tracked operations are implemented.

Service documentation: /azure/services/cache-for-redis/

| Operation | Status |
| --- | --- |
| AccessPolicy.CreateUpdate | Not implemented |
| AccessPolicy.Delete | Not implemented |
| AccessPolicy.Get | Not implemented |
| AccessPolicy.List | Not implemented |
| AsyncOperationStatus.Get | Not implemented |
| FirewallRules.CreateOrUpdate | Implemented |
| FirewallRules.Delete | Implemented |
| FirewallRules.Get | Implemented |
| FirewallRules.List | Implemented |
| LinkedServer.Create | Not implemented |
| LinkedServer.Delete | Not implemented |
| LinkedServer.Get | Not implemented |
| LinkedServer.List | Not implemented |
| Operations.List | Implemented |
| PatchSchedules.CreateOrUpdate | Implemented |
| PatchSchedules.Delete | Implemented |
| PatchSchedules.Get | Implemented |
| PatchSchedules.ListByRedisResource | Implemented |
| PrivateLinkResources.ListByRedisCache | Not implemented |
| Redis.CheckNameAvailability | Implemented |
| Redis.Create | Implemented |
| Redis.Delete | Implemented |
| Redis.ExportData | Not implemented |
| Redis.FlushCache | Implemented |
| Redis.ForceReboot | Implemented |
| Redis.Get | Implemented |
| Redis.ImportData | Not implemented |
| Redis.List | Implemented |
| Redis.ListByResourceGroup | Implemented |
| Redis.ListBySubscription | Implemented |
| Redis.ListKeys | Implemented |
| Redis.ListUpgradeNotifications | Not implemented |
| Redis.RegenerateKey | Implemented |
| Redis.Update | Implemented |
