Skip to main content

Redis

Type: state.redis

Status: stable

Reference: https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-redis/

Example

apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
name: <name>
spec:
type: state.redis
version: v1
metadata:
# Password for Redis host. No default. Use secretKeyRef for secret reference (Optional)
#- name: redisPassword
# value: "KeFg23!"
# Username for Redis host. Defaults to empty. Make sure your Redis server version is 6 or above, and have created ACL rule correctly. (Optional)
#- name: redisUsername
# value: "my-username"
# Connection-string for the redis host
- name: redisHost
value: "redis-master.default.svc.cluster.local:6379"
# Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference (Optional)
#- name: clientCert
# value: |
#
# Client key for Redis host. No Default. Can be secretKeyRef to use a secret reference (Optional)
#- name: clientKey
# value: |
#
# Dial timeout for establishing new connections. Defaults to "5s". (Optional)
#- name: dialTimeout
# value: "5s"
# If the Redis instance supports TLS with public certificates, can be configured to be enabled or disabled. Defaults to false. (Optional)
#- name: enableTLS
# value: "false"
# Use this state store as the Workflows Store, it will enable the Workflows API. Defaults to `false`. (Optional)
#- name: enableWorkflow
# value: "false"
# Enables failover configuration. It requires "sentinelMasterName" to be set, and "redisHost" to be the sentinel host address. (Optional)
#- name: failover
# value: "false"
# Frequency of idle checks made by idle connections reaper. Default is "1m". "-1" disables idle connections reaper. (Optional)
#- name: idleCheckFrequency
# value: "-1"
# Amount of time after which the client closes idle connections. Should be less than server's timeout. Default is "5m". "-1" disables idle timeout check. (Optional)
#- name: idleTimeout
# value: "10m"
# Prefix added to keys in the state store. (Optional)
#- name: keyPrefix
# value: "appid"
# Connection age at which the client retires (closes) the connection. Default is to not close aged connections. (Optional)
#- name: maxConnAge
# value: "30m"
# Minimum number of idle connections to keep open in order to avoid the performance degradation associated with creating new connections. Defaults to "0". (Optional)
#- name: minIdleConns
# value: "2"
# By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state (Optional)
#- name: outboxDiscardWhenMissingState
# value: "false"
# For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes (Optional)
#- name: outboxPublishPubsub
# value: ""
# For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation (Optional)
#- name: outboxPublishTopic
# value: ""
# For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction (Optional)
#- name: outboxPubsub
# value: "outboxPublishPubsub"
# Maximum number of socket connections. Default is 10 connections per every CPU as reported by runtime.NumCPU. (Optional)
#- name: poolSize
# value: "20"
# Amount of time client waits for a connection if all connections are busy before returning an error. Default is readTimeout + 1 second. (Optional)
#- name: poolTimeout
# value: "5s"
# The amount time a message must be pending before attempting to redeliver it. Defaults to "15s". "0" disables redelivery. (Optional)
#- name: processingTimeout
# value: "30s"
# Indexing schemas for querying JSON objects (Optional)
#- name: queryIndexes
# value: "see Querying JSON objects"
# Timeout for socket reads. If reached, redis commands will fail with a timeout instead of blocking. Defaults to "3s", "-1" for no timeout. (Optional)
#- name: readTimeout
# value: "3s"
# The interval between checking for pending messages to redelivery. Defaults to "60s". "0" disables redelivery. (Optional)
#- name: redeliverInterval
# value: "30s"
# Database selected after connecting to Redis. If "redisType" is "cluster" this option is ignored. Defaults to "0". (Optional)
#- name: redisDB
# value: "0"
# Maximum number of retries for Redis commands. (Optional)
#- name: redisMaxRetries
# value: "3"
# Alias for maxRetryBackoff. If both values are set maxRetryBackoff is ignored. (Optional)
#- name: redisMaxRetryInterval
# value: "5s"
# Minimum backoff for Redis commands between each retry."-1" disables backoff. (Optional)
#- name: redisMinRetryInterval
# value: "2s"
# Redis service type. Set to "node" for single-node mode, or "cluster" for Redis Cluster. (Optional)
#- name: redisType
# value: "node"
# The Redis sentinel master name. Required when "failover" is enabled. (Optional)
#- name: sentinelMasterName
# value: "127.0.0.1:6379"
# Allows specifying a default Time-to-live (TTL) in seconds that will be applied to every state store request unless TTL is explicitly defined via the request metadata. (Optional)
#- name: ttlInSeconds
# value: "600"
# Timeout for socket writes. If reached, redis commands will fail with a timeout instead of blocking. Defaults is readTimeout. (Optional)
#- name: writeTimeout
# value: "3s"

Authentication profiles

Available authentication profiles:

  • Username and password

  • Azure AD: Client credentials

  • Azure AD: Client certificate

Username and password

Authenticate using username and password.

redisPassword (string)

Password for Redis host. No default. Use secretKeyRef for secret reference

Example value: KeFg23!

redisUsername (string)

Username for Redis host. Defaults to empty. Make sure your Redis server version is 6 or above, and have created ACL rule correctly.

Example value: my-username

Azure AD: Client credentials

Authenticate using Azure AD with client credentials, also known as "service principals".

azureClientId

Required - Client ID (application ID)

Example value: c7dd251f-811f-4ba2-a905-acd4d3f8f08b

azureClientSecret

Required - Client secret (application password)

Example value: Ecy3XG7zVZK3/vl/a2NSB+a1zXLa8RnMum/IgD0E

azureTenantId

Required - ID of the Azure AD tenant

Example value: cd4b2887-304c-47e1-b4d5-65447fdd542a

azureEnvironment

Optional name for the Azure environment if using a different Azure cloud

Default value: AzurePublicCloud

Example value: AzurePublicCloud

Allowed values:

  • AzurePublicCloud

  • AzureChinaCloud

  • AzureUSGovernmentCloud

useEntraID (bool)

If set, enables authentication to Azure Cache for Redis using Microsoft EntraID. The Redis server must explicitly enable EntraID authentication. Note that Azure Cache for Redis also requires the use of TLS, so enableTLS should be set. No username or password should be set.

Default value: false

Example value: true

Azure AD: Client certificate

Authenticate using Azure AD with a client certificate. "azureCertificate" is required.

azureClientId

Required - Client ID (application ID)

Example value: c7dd251f-811f-4ba2-a905-acd4d3f8f08b

azureTenantId

Required - ID of the Azure AD tenant

Example value: cd4b2887-304c-47e1-b4d5-65447fdd542a

azureCertificate

Certificate and private key (in either a PEM file containing both the certificate and key, or in PFX/PKCS#12 format)

Example value:

-----BEGIN PRIVATE KEY-----\n MIIEvgI... \n -----END PRIVATE KEY-----
\n -----BEGIN CERTIFICATE----- \n MIICoTC... \n -----END CERTIFICATE----- \n

azureCertificatePassword

Password for the certificate if encrypted.

Example value: password

azureEnvironment

Optional name for the Azure environment if using a different Azure cloud

Default value: AzurePublicCloud

Example value: AzurePublicCloud

Allowed values:

  • AzurePublicCloud

  • AzureChinaCloud

  • AzureUSGovernmentCloud

useEntraID (bool)

If set, enables authentication to Azure Cache for Redis using Microsoft EntraID. The Redis server must explicitly enable EntraID authentication. Note that Azure Cache for Redis also requires the use of TLS, so enableTLS should be set. No username or password should be set.

Default value: false

Example value: true

Metadata

redisHost (string)

Required - Connection-string for the redis host

Example value: redis-master.default.svc.cluster.local:6379

clientCert (string)

Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference

clientKey (string)

Client key for Redis host. No Default. Can be secretKeyRef to use a secret reference

dialTimeout (duration)

Dial timeout for establishing new connections. Defaults to "5s".

Example value: 5s

enableTLS (bool)

If the Redis instance supports TLS with public certificates, can be configured to be enabled or disabled. Defaults to false.

Example value: false

enableWorkflow (bool)

Use this state store as the Workflows Store, it will enable the Workflows API. Defaults to false.

Example value: false

failover (bool)

Enables failover configuration. It requires "sentinelMasterName" to be set, and "redisHost" to be the sentinel host address.

Default value: false

Example value: true

Redis Sentinel documentation: https://redis.io/docs/manual/sentinel/

idleCheckFrequency (duration)

Frequency of idle checks made by idle connections reaper. Default is "1m". "-1" disables idle connections reaper.

Example value: -1

idleTimeout (duration)

Amount of time after which the client closes idle connections. Should be less than server's timeout. Default is "5m". "-1" disables idle timeout check.

Example value: 10m

keyPrefix (string)

Prefix added to keys in the state store.

Default value: appid

Example value: appid

Allowed values:

  • appid

  • name

  • none

Documentation: https://docs.dapr.io/developing-applications/building-blocks/state-management/howto-share-state/

maxConnAge (duration)

Connection age at which the client retires (closes) the connection. Default is to not close aged connections.

Example value: 30m

minIdleConns (number)

Minimum number of idle connections to keep open in order to avoid the performance degradation associated with creating new connections. Defaults to "0".

Example value: 2

outboxDiscardWhenMissingState (bool)

By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state

Default value: false

outboxPublishPubsub (string)

For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes

outboxPublishTopic (string)

For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation

outboxPubsub (string)

For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction

Default value: outboxPublishPubsub

poolSize (number)

Maximum number of socket connections. Default is 10 connections per every CPU as reported by runtime.NumCPU.

Example value: 20

poolTimeout (duration)

Amount of time client waits for a connection if all connections are busy before returning an error. Default is readTimeout + 1 second.

Example value: 5s

processingTimeout (duration)

The amount time a message must be pending before attempting to redeliver it. Defaults to "15s". "0" disables redelivery.

Example value: 30s

queryIndexes (string)

Indexing schemas for querying JSON objects

Example value: see Querying JSON objects

readTimeout (duration)

Timeout for socket reads. If reached, redis commands will fail with a timeout instead of blocking. Defaults to "3s", "-1" for no timeout.

Example value: 3s

redeliverInterval (duration)

The interval between checking for pending messages to redelivery. Defaults to "60s". "0" disables redelivery.

Example value: 30s

redisDB (number)

Database selected after connecting to Redis. If "redisType" is "cluster" this option is ignored. Defaults to "0".

Example value: 0

redisMaxRetries (number)

Maximum number of retries for Redis commands.

Default value: 3

Example value: 5

redisMaxRetryInterval (duration)

Alias for maxRetryBackoff. If both values are set maxRetryBackoff is ignored.

Example value: 5s

redisMinRetryInterval (duration)

Minimum backoff for Redis commands between each retry."-1" disables backoff.

Default value: 2s

Example value: 8ms

redisType (string)

Redis service type. Set to "node" for single-node mode, or "cluster" for Redis Cluster.

Default value: node

Example value: cluster

Allowed values:

  • node

  • cluster

sentinelMasterName (string)

The Redis sentinel master name. Required when "failover" is enabled.

Example value: 127.0.0.1:6379

Redis Sentinel documentation: https://redis.io/docs/manual/sentinel/

ttlInSeconds (number)

Allows specifying a default Time-to-live (TTL) in seconds that will be applied to every state store request unless TTL is explicitly defined via the request metadata.

Example value: 600

writeTimeout (duration)

Timeout for socket writes. If reached, redis commands will fail with a timeout instead of blocking. Defaults is readTimeout.

Example value: 3s