# Redis Distributed Lock

Type: `lock.redis`

Status: alpha

Reference: https://docs.dapr.io/reference/components-reference/supported-locks/redis-lock/

## Example

```
apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
  name: <name>
spec:
  type: lock.redis
  version: v1
  metadata:
    # The Redis password (Optional)
    #- name: redisPassword
    #  value: "redis-password"
    # The Redis username (Optional)
    #- name: redisUsername
    #  value: "redis-user"
    # 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: "mycompany.com:6379"
    # Dial timeout duration (Optional)
    #- name: dialTimeout
    #  value: "5s"
    # Whether to enable TLS encryption (Optional)
    #- name: enableTLS
    #  value: "false"
    # Whether to enable failover mode (for Sentinel) (Optional)
    #- name: failover
    #  value: "false"
    # Idle check frequency (Optional)
    #- name: idleCheckFrequency
    #  value: "1m"
    # Idle timeout duration (Optional)
    #- name: idleTimeout
    #  value: "5m"
    # Skip TLS certificate verification (insecure). Only use for testing. (Optional)
    #- name: insecureSkipTLSVerify
    #  value: "false"
    # Prefix added to keys in the state store. (Optional)
    #- name: keyPrefix
    #  value: "appid"
    # Maximum connection age (Optional)
    #- name: maxConnAge
    #  value: "30m"
    # Maximum number of retries when attempting to acquire a lock (Optional)
    #- name: maxRetries
    #  value: "3"
    # Maximum backoff duration between retries (Optional)
    #- name: maxRetryBackoff
    #  value: "2s"
    # Minimum idle connections (Optional)
    #- name: minIdleConns
    #  value: "0"
    # Connection pool size (Optional)
    #- name: poolSize
    #  value: "10"
    # Connection pool timeout (Optional)
    #- name: poolTimeout
    #  value: "4s"
    # Processing timeout for lock ownership (Optional)
    #- name: processingTimeout
    #  value: "60s"
    # Read timeout duration (Optional)
    #- name: readTimeout
    #  value: "3s"
    # Redeliver interval for re-attempting lock acquisition (Optional)
    #- name: redeliverInterval
    #  value: "15s"
    # The Redis database number (Optional)
    #- name: redisDB
    #  value: "0"
    # Maximum Redis retries (Optional)
    #- name: redisMaxRetries
    #  value: "3"
    # Maximum Redis retry interval (Optional)
    #- name: redisMaxRetryInterval
    #  value: "512ms"
    # Minimum Redis retry interval (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. (Optional)
    #- name: redisPort
    #  value: "6379"
    # The Redis type (Optional)
    #- name: redisType
    #  value: "node"
    # The Sentinel master name (used if redisType is 'sentinel') (Optional)
    #- name: sentinelMasterName
    #  value: "mymaster"
    # Whether to use Entra ID for authentication (Optional)
    #- name: useEntraID
    #  value: "false"
    # Write timeout duration (Optional)
    #- name: writeTimeout
    #  value: "3s"

```

## Authentication profiles

Available authentication profiles:

- Password Authentication

- Sentinel Authentication

- TLS Authentication

### Password Authentication

Authenticate using Redis password.

#### `redisPassword`

The Redis password

Example value: `redis-password`

#### `redisUsername`

The Redis username

Example value: `redis-user`

### Sentinel Authentication

Authenticate using Redis Sentinel password.

#### `sentinelPassword`

The Redis Sentinel password

Example value: `sentinel-password`

#### `sentinelUsername`

The Redis Sentinel username

Example value: `sentinel-user`

### TLS Authentication

Authenticate using Redis TLS certificate.

#### `clientCert`

The Redis client certificate

Example value:

```
-----BEGIN CERTIFICATE-----\nXXX...
```

#### `clientKey`

The Redis client key

Example value:

```
-----BEGIN PRIVATE KEY-----\nXXX...
```

## 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: `mycompany.com:6379`

### `dialTimeout`

Dial timeout duration

Default value: `5s`

Example value: `5s`

### `enableTLS` (bool)

Whether to enable TLS encryption

Default value: `false`

Example value: `false`

### `failover` (bool)

Whether to enable failover mode (for Sentinel)

Default value: `false`

Example value: `false`

### `idleCheckFrequency`

Idle check frequency

Default value: `1m`

Example value: `1m`

### `idleTimeout`

Idle timeout duration

Default value: `5m`

Example value: `5m`

### `insecureSkipTLSVerify` (bool)

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

Default value: `false`

Example value: `false`

### `keyPrefix` (string)

Prefix added to keys in the state store.

Default value: `appid`

Example value: `appid`

Allowed values:

- appid

- name

- none

### `maxConnAge`

Maximum connection age

Default value: `30m`

Example value: `30m`

### `maxRetries`

Maximum number of retries when attempting to acquire a lock

Default value: `3`

Example value: `3`

### `maxRetryBackoff`

Maximum backoff duration between retries

Default value: `2s`

Example value: `2s`

### `minIdleConns`

Minimum idle connections

Default value: `0`

Example value: `0`

### `poolSize`

Connection pool size

Default value: `10`

Example value: `10`

### `poolTimeout`

Connection pool timeout

Default value: `4s`

Example value: `4s`

### `processingTimeout`

Processing timeout for lock ownership

Default value: `60s`

Example value: `60s`

### `readTimeout`

Read timeout duration

Default value: `3s`

Example value: `3s`

### `redeliverInterval`

Redeliver interval for re-attempting lock acquisition

Default value: `15s`

Example value: `15s`

### `redisDB`

The Redis database number

Default value: `0`

Example value: `0`

### `redisMaxRetries`

Maximum Redis retries

Default value: `3`

Example value: `3`

### `redisMaxRetryInterval`

Maximum Redis retry interval

Default value: `512ms`

Example value: `512ms`

### `redisMinRetryInterval`

Minimum Redis retry interval

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.

Example value: `6379`

### `redisType`

The Redis type

Default value: `node`

Example value: `node`

Allowed values:

- node

- cluster

- sentinel

### `sentinelMasterName`

The Sentinel master name (used if redisType is 'sentinel')

Example value: `mymaster`

### `useEntraID` (bool)

Whether to use Entra ID for authentication

Default value: `false`

Example value: `false`

### `writeTimeout`

Write timeout duration

Default value: `3s`

Example value: `3s`
