# Redis pub/sub

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"
    # The interval at which the component resets the idle time of the pending messages it is holding, so that messages still buffered or being processed are not redelivered before "processingTimeout" elapses. Must be shorter than "processingTimeout" while redelivery is enabled, otherwise a held message becomes reclaimable before it is renewed; the component fails to initialise if it is not. Defaults to half of "processingTimeout". "0" disables the keep-alive, restoring the previous behaviour where queueing time counts towards "processingTimeout". (Optional)
    #- name: entryKeepAliveInterval
    #  value: "processingTimeout / 2"
    # 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: "60s"
    # 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: "15s"
    # 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

- OIDC private_key_jwt

- 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

### OIDC private_key_jwt

Authenticate using OpenID Connect with the private_key_jwt client authentication
method (RFC 7523). An OAuth2 access token is obtained from the identity provider
using a signed JWT client assertion and used as the password for the Redis AUTH
command. The token is refreshed in the background before it expires.

#### `oidcClientAssertionCert` (string)

**Required** - PEM-encoded X.509 certificate paired with the client assertion signing key. Use secretKeyRef for secret reference.

Example value: `-----BEGIN CERTIFICATE-----\n...`

#### `oidcClientAssertionKey` (string)

**Required** - PEM-encoded RSA private key used to sign the client assertion. Use secretKeyRef for secret reference.

Example value: `-----BEGIN PRIVATE KEY-----\n...`

#### `oidcClientID` (string)

**Required** - The OAuth2 client ID that has been provisioned in the identity provider.

Example value: `my-client-id`

#### `oidcTokenEndpoint` (string)

**Required** - URL of the OAuth2 identity provider access token endpoint.

Example value: `https://identity.example.com/v1/token`

#### `oidcAudience` (string)

Overrides the JWT client assertion audience (aud). Defaults to the token endpoint URL.

Example value: `https://identity.example.com/realms/local`

#### `oidcCACert` (string)

PEM-encoded CA certificate used to verify the TLS connection to the token endpoint. This is distinct from the TLS configuration of the Redis connection itself.

Example value: `-----BEGIN CERTIFICATE-----\n...`

#### `oidcKid` (string)

The JWT key ID (kid) header to use for the client assertion, when required by the identity provider (for example, the thumbprint of the client certificate).

Example value: `1234567890`

#### `oidcResource` (string)

Optional OAuth2 resource parameter to include in the token request when required by the identity provider.

Example value: `URI:RS-12345-API`

#### `oidcScopes` (string)

Comma-delimited list of OAuth2/OIDC scopes to request with the access token. Although not required, this field is recommended.

Default value: `openid`

Example value: `openid,redis-prod`

#### `redisUsername` (string)

Username to pass to the Redis AUTH command together with the access token. When omitted, the token is sent using the 1-argument AUTH \<token> form (authenticating as the default user), accepted by the widest range of RESP-compatible auth layers. Set a username to use the 2-argument AUTH \<username> \<token> (ACL) form.

Example value: `my-user`

#### `useOIDC` (bool)

If set to true, enables OIDC private_key_jwt authentication. Must not be combined with "redisPassword" or "useEntraID".

Default value: `false`

Example value: `true`

### 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`

### `entryKeepAliveInterval` (duration)

The interval at which the component resets the idle time of the pending messages it is holding, so that messages still buffered or being processed are not redelivered before "processingTimeout" elapses. Must be shorter than "processingTimeout" while redelivery is enabled, otherwise a held message becomes reclaimable before it is renewed; the component fails to initialise if it is not. Defaults to half of "processingTimeout". "0" disables the keep-alive, restoring the previous behaviour where queueing time counts towards "processingTimeout".

Default value: `processingTimeout / 2`

Example value: `30s`

### `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: `60s`

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: `15s`

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`
