apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: <NAME>
spec:
type: lock.redis
version: v1
metadata:
- name: redisHost
value: <HOST>
- name: redisPassword #Optional.
value: <PASSWORD>
- name: useEntraID
value: <bool> # Optional. Allowed: true, false.
- name: enableTLS
value: <bool> # Optional. Allowed: true, false.
- name: failover
value: <bool> # Optional. Allowed: true, false.
- name: sentinelMasterName
value: <string> # Optional
- name: maxRetries
value: # Optional
- name: maxRetryBackoff
value: # Optional
- name: redeliverInterval
value: # Optional
- name: processingTimeout
value: # Optional
- name: redisType
value: # Optional
- name: redisDB
value: # Optional
- name: redisMaxRetries
value: # Optional
- name: redisMinRetryInterval
value: # Optional
- name: redisMaxRetryInterval
value: # Optional
- name: dialTimeout
value: # Optional
- name: readTimeout
value: # Optional
- name: writeTimeout
value: # Optional
- name: poolSize
value: # Optional
- name: poolTimeout
value: # Optional
- name: maxConnAge
value: # Optional
- name: minIdleConns
value: # Optional
- name: idleCheckFrequency
value: # Optional
- name: idleTimeout
value: # Optional
Dapr can use any Redis instance: containerized, running on your local dev machine, or a managed cloud service.
A Redis instance is automatically created as a Docker container when you run dapr init
You can use Helm to quickly create a Redis instance in our Kubernetes cluster. This approach requires Installing Helm.
Install Redis into your cluster. Note that we’re explicitly setting an image tag to get a version greater than 5, which is what Dapr’ pub/sub functionality requires. If you’re intending on using Redis as just a state store (and not for pub/sub), you do not have to set the image version.
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install redis bitnami/redis --set image.tag=6.2
Run kubectl get pods
to see the Redis containers now running in your cluster.
Add redis-master:6379
as the redisHost
in your redis.yaml file. For example:
metadata:
- name: redisHost
value: redis-master:6379
Next, get the Redis password, which is slightly different depending on the OS we’re using:
Windows: Run kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" > encoded.b64
, which creates a file with your encoded password. Next, run certutil -decode encoded.b64 password.txt
, which will put your redis password in a text file called password.txt
. Copy the password and delete the two files.
Linux/MacOS: Run kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode
and copy the outputted password.
Add this password as the redisPassword
value in your redis.yaml file. For example:
metadata:
- name: redisPassword
value: lhDOkwTlp0
Create an Azure Cache for Redis instance using the official Microsoft documentation.
Once your instance is created, grab the Host name (FQDN) and your access key from the Azure portal.
- For the Host name:
- Navigate to the resource’s Overview page.
- Copy the Host name value.
- For your access key:
- Navigate to Settings > Access Keys.
- Copy and save your key.
Add your key and your host name to a redis.yaml
file that Dapr can apply to your cluster.
- If you’re running a sample, add the host and key to the provided
redis.yaml
. - If you’re creating a project from the ground up, create a
redis.yaml
file as specified in the Component format section.
Set the redisHost
key to [HOST NAME FROM PREVIOUS STEP]:6379
and the redisPassword
key to the key you saved earlier.
Note: In a production-grade application, follow secret management instructions to securely manage your secrets.
Enable EntraID support:
- Enable Entra ID authentication on your Azure Redis server. This may takes a few minutes.
- Set
useEntraID
to "true"
to implement EntraID support for Azure Cache for Redis.
Set enableTLS
to "true"
to support TLS.
Note:useEntraID
assumes that either your UserPrincipal (via AzureCLICredential) or the SystemAssigned managed identity have the RedisDataOwner role permission. If a user-assigned identity is used, you need to specify the azureClientID
property.