# Redis

Type: `pubsub.redis`

Status: stable

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

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: pubsub.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"
    # Password for Redis Sentinel. Applicable only when "failover" is true, and Redis Sentinel has authentication enabled. Use secretKeyRef for secret reference. Defaults to empty. (Optional)
    #- name: sentinelPassword
    #  value: "KeFg23!"
    # Username for Redis Sentinel. Applicable only when "failover" is true, and Redis Sentinel has authentication enabled. Defaults to empty. (Optional)
    #- name: sentinelUsername
    #  value: "my-sentinel-username"
    # Connection-string for the redis host. If "redisType" is "cluster" it can be multiple hosts separated by commas or just a single host. The port can be included in the host string (e.g. "host:6379") or provided separately via "redisPort".
    - 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: | 
    #    
    # The number of concurrent workers that are processing messages. (Optional)
    #- name: concurrency
    #  value: "10"
    # The consumer group ID (Optional)
    #- name: consumerID
    #  value: "myGroup"
    # Dial timeout for establishing new connections. (Optional)
    #- name: dialTimeout
    #  value: "5s"
    # If the Redis instance supports TLS, can be configured to be enabled or disabled. (Optional)
    #- name: enableTLS
    #  value: "false"
    # Property to enabled failover configuration. Needs sentinelMasterName to be set. (Optional)
    #- name: failover
    #  value: "false"
    # Frequency of idle checks made by idle connections reaper. "-1" disables idle connections reaper. (Optional)
    #- name: idleCheckFrequency
    #  value: "1m"
    # Amount of time after which the client closes idle connections. Should be less than server's timeout. "-1" disables idle timeout check. (Optional)
    #- name: idleTimeout
    #  value: "5m"
    # Skip TLS certificate verification (insecure). Only use for testing. (Optional)
    #- name: insecureSkipTLSVerify
    #  value: "false"
    # Connection age at which the client retires (closes) the connection. Default is to not close aged connections. (Optional)
    #- name: maxConnAge
    #  value: "30m"
    # Maximum number of items inside a stream. The old entries are automatically evicted when the specified length is reached, so that the stream is left at a constant size. Defaults to unlimited. Cannot be used together with streamTTL; only one stream trimming strategy can be active at a time. (Optional)
    #- name: maxLenApprox
    #  value: "10000"
    # Minimum number of idle connections to keep open in order to avoid the performance degradation associated with creating new connections. (Optional)
    #- name: minIdleConns
    #  value: "0"
    # 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. "0" disables redelivery. (Optional)
    #- name: processingTimeout
    #  value: "15s"
    # The size of the message queue for processing. (Optional)
    #- name: queueDepth
    #  value: "100"
    # Timeout for socket reads. If reached, redis commands will fail with a timeout instead of blocking. "-1" for no timeout. (Optional)
    #- name: readTimeout
    #  value: "3"
    # The interval between checking for pending messages to redelivery. "0" disables redelivery. (Optional)
    #- name: redeliverInterval
    #  value: "60s"
    # Database selected after connecting to redis. If "redisType" is "cluster" this option is ignored. (Optional)
    #- name: redisDB
    #  value: "0"
    # Maximum number of times to retry commands before giving up. Default is to not retry failed commands. (Optional)
    #- name: redisMaxRetries
    #  value: "5"
    # Maximum backoff for redis commands between each retry. "-1" disables backoff. (Optional)
    #- name: redisMaxRetryInterval
    #  value: "512ms"
    # Minimum backoff for redis commands between each retry. "-1" disables backoff. (Optional)
    #- name: redisMinRetryInterval
    #  value: "8ms"
    # The Redis port. Optional: if "redisHost" already contains a port, this field must either match or be omitted. When "redisHost" does not include a port and this field is not set, the default Redis port 6379 is used. In cluster mode, this port is applied to every host in the comma-separated list. (Optional)
    #- name: redisPort
    #  value: "6379"
    # The type of redis. There are two valid values, one is "node" for single node mode, the other is "cluster" for redis cluster mode. (Optional)
    #- name: redisType
    #  value: "node"
    # The sentinel master name. See Redis Sentinel Documentation. (Optional)
    #- name: sentinelMasterName
    #  value: "mymaster"
    # TTL duration for stream entries. Entries older than this duration will be evicted. This is an approximate value, as it's implemented using Redis stream's MINID trimming with the '~' modifier. The actual retention may include slightly more entries than strictly defined by the TTL, as Redis optimizes the trimming operation for efficiency by potentially keeping some additional entries. Cannot be used together with maxLenApprox; only one stream trimming strategy can be active at a time. (Optional)
    #- name: streamTTL
    #  value: "30d"
    # 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`

#### `sentinelPassword` (string)

Password for Redis Sentinel. Applicable only when "failover" is true, and Redis Sentinel has authentication enabled. Use secretKeyRef for secret reference. Defaults to empty.

Example value: `KeFg23!`

Redis Sentinel authentication documentation: https://redis.io/docs/latest/operate/oss\_and\_stack/management/sentinel/#configuring-sentinel-instances-with-authentication

#### `sentinelUsername` (string)

Username for Redis Sentinel. Applicable only when "failover" is true, and Redis Sentinel has authentication enabled. Defaults to empty.

Example value: `my-sentinel-username`

Redis Sentinel authentication documentation: https://redis.io/docs/latest/operate/oss\_and\_stack/management/sentinel/#configuring-sentinel-instances-with-authentication

### 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. If "redisType" is "cluster" it can be multiple hosts separated by commas or just a single host. The port can be included in the host string (e.g. "host:6379") or provided separately via "redisPort".

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

### `concurrency` (number)

The number of concurrent workers that are processing messages.

Default value: `10`

Example value: `15`

### `consumerID` (string)

The consumer group ID

Example value: `myGroup`

### `dialTimeout` (duration)

Dial timeout for establishing new connections.

Default value: `5s`

Example value: `5s`

### `enableTLS` (bool)

If the Redis instance supports TLS, can be configured to be enabled or disabled.

Default value: `false`

Example value: `false`

### `failover` (bool)

Property to enabled failover configuration. Needs sentinelMasterName to be set.

Default value: `false`

Example value: `false`

### `idleCheckFrequency` (duration)

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

Default value: `1m`

Example value: `-1`

### `idleTimeout` (duration)

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

Default value: `5m`

Example value: `10m`

### `insecureSkipTLSVerify` (bool)

Skip TLS certificate verification (insecure). Only use for testing.

Default value: `false`

Example value: `false`

### `maxConnAge` (duration)

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

Example value: `30m`

### `maxLenApprox` (number)

Maximum number of items inside a stream. The old entries are automatically evicted when the specified length is reached, so that the stream is left at a constant size. Defaults to unlimited. Cannot be used together with streamTTL; only one stream trimming strategy can be active at a time.

Example value: `10000`

### `minIdleConns` (number)

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

Default value: `0`

Example value: `2`

### `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. "0" disables redelivery.

Default value: `15s`

Example value: `30s`

### `queueDepth` (number)

The size of the message queue for processing.

Default value: `100`

Example value: `1000`

### `readTimeout` (duration)

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

Default value: `3`

Example value: `3s`

### `redeliverInterval` (duration)

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

Default value: `60s`

Example value: `30s`

### `redisDB` (number)

Database selected after connecting to redis. If "redisType" is "cluster" this option is ignored.

Default value: `0`

Example value: `0`

### `redisMaxRetries` (number)

Maximum number of times to retry commands before giving up. Default is to not retry failed commands.

Example value: `5`

### `redisMaxRetryInterval` (duration)

Maximum backoff for redis commands between each retry. "-1" disables backoff.

Default value: `512ms`

Example value: `5s`

### `redisMinRetryInterval` (duration)

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

Default value: `8ms`

Example value: `8ms`

### `redisPort` (string)

The Redis port. Optional: if "redisHost" already contains a port, this field must either match or be omitted. When "redisHost" does not include a port and this field is not set, the default Redis port 6379 is used. In cluster mode, this port is applied to every host in the comma-separated list.

Example value: `6379`

### `redisType` (string)

The type of redis. There are two valid values, one is "node" for single node mode, the other is "cluster" for redis cluster mode.

Default value: `node`

Example value: `cluster`

### `sentinelMasterName` (string)

The sentinel master name. See Redis Sentinel Documentation.

Example value: `mymaster`

### `streamTTL` (duration)

TTL duration for stream entries. Entries older than this duration will be evicted. This is an approximate value, as it's implemented using Redis stream's MINID trimming with the '~' modifier. The actual retention may include slightly more entries than strictly defined by the TTL, as Redis optimizes the trimming operation for efficiency by potentially keeping some additional entries. Cannot be used together with maxLenApprox; only one stream trimming strategy can be active at a time.

Example value: `30d`

### `writeTimeout` (duration)

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

Example value: `3s`
