Cache for Redis
Introduction
Section titled “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?
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 section.
Getting started
Section titled “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.
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:
lstk az start-interceptionThis 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:
lstk az stop-interceptionThis reconfigures the az CLI to send commands to the official Azure management REST API.
Create a resource group
Section titled “Create a resource group”Create a resource group to contain your cache:
az group create \ --name rg-redis-demo \ --location westeurope{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-redis-demo", "location": "westeurope", "name": "rg-redis-demo", "properties": { "provisioningState": "Succeeded" }, ...}Create a cache
Section titled “Create a cache”Create a Basic C0 cache that requires TLS 1.2 or later:
az redis create \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --location westeurope \ --sku Basic \ --vm-size c0 \ --minimum-tls-version 1.2{ "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:
az redis show \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --query "{hostName:hostName, sslPort:sslPort, enableNonSslPort:enableNonSslPort, sku:sku.name, provisioningState:provisioningState}"{ "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
Section titled “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:
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:
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PINGredis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls SET greeting "Hello from LocalStack"redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls GET greetingPONGOKHello from LocalStackThe 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
Section titled “Regenerate an access key”Regenerate the secondary key. The primary key, and the sessions authenticated with it, stay valid:
az redis regenerate-keys \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --key-type Secondary \ --output noneUse the non-TLS port
Section titled “Use the non-TLS port”Enable the non-TLS port:
az redis update \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --set enableNonSslPort=true \ --query "{enableNonSslPort:enableNonSslPort, port:port}"{ "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:
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 greetingHello from LocalStackDisable the non-TLS port again:
az redis update \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --set enableNonSslPort=false \ --query "{enableNonSslPort:enableNonSslPort}"{ "enableNonSslPort": false}Restrict access with firewall rules
Section titled “Restrict access with firewall rules”Create a firewall rule that admits only the 203.0.113.0/24 documentation range:
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{ "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:
az redis firewall-rules list \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --query "[].{name:name, startIp:startIp, endIp:endIp}" \ --output tableName StartIp EndIp----------------------------- ----------- -------------redis-demo-cache/allow-office 203.0.113.1 203.0.113.254Your client’s address is outside the rule, so the cache now refuses the connection:
redis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PINGCould not connect to Redis at redis-demo-cache.redis.azure.localhost.localstack.cloud:4510: SSL_connect failed: unexpected eof while readingDelete the rule to admit every address again:
az redis firewall-rules delete \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --rule-name allow-officeredis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls PINGPONGSchedule updates
Section titled “Schedule updates”Set a maintenance window for Sundays at 02:00 UTC:
az redis patch-schedule create \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --schedule-entries '[{"dayOfWeek":"Sunday","startHourUtc":2,"maintenanceWindow":"PT5H"}]'{ "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:
az redis patch-schedule show \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --query "scheduleEntries"[ { "dayOfWeek": "Sunday", "maintenanceWindow": "5:00:00", "startHourUtc": 2 }]Reboot and flush the cache
Section titled “Reboot and flush the cache”Reboot the cache. A reboot doesn’t remove its data:
az redis force-reboot \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --reboot-type AllNodesredis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls DBSIZE{ "message": "The requested reboot operation for 'Value' has been successfully scheduled and should be executed shortly."}1Flush the cache to remove every key:
az redis flush \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --yesredis-cli -h "$REDIS_HOST" -p "$REDIS_PORT" --tls DBSIZE{ "status": "Succeeded", ...}0Delete the cache
Section titled “Delete the cache”Delete the cache and the resource group:
az redis delete \ --name redis-demo-cache \ --resource-group rg-redis-demo \ --yesaz group delete \ --name rg-redis-demo \ --yesFeatures
Section titled “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
enableNonSslPortistrue. 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-keysreplaces only the key you name, and settingdisableAccessKeyAuthenticationturns 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
publicNetworkAccesstoDisabledrefuses 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
Section titled “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 asmaxmemory-policyandnotify-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
Section titled “Samples”Explore end-to-end examples in the LocalStack for Azure Samples repository.
API Coverage
Section titled “API Coverage”21 of 34 operations implemented
| Operation ▲ | Implemented ▼ |
|---|