## InMemoryLockStore (default)

- **Description**  
`InMemoryLockStore` is the default lock store. It maintains conversation locks within a single process.

**Note**  
This lock store should not be used when multiple Rasa servers are run in parallel.

- **Configuration**  
To use the `InMemoryTrackerStore`, no configuration is needed.

## ConcurrentRedisLockStore  
`ConcurrentRedisLockStore` is a new, recommended lock store that uses Redis as a persistence layer and is safe for use with multiple Rasa server replicas.  
See the [migration section](/content/docs/reference/integrations/lock-stores/#migration-guide/index.html) to learn how to switch to this lock store.

### Description  
The `ConcurrentRedisLockStore` uses Redis as a persistence layer for instances of issued [tickets](https://legacy-docs-oss.rasa.com/docs/rasa/reference/rasa/core/lock/#ticket-objects) and the last issued ticket number.

The ticket number initialization begins at 1, in contrast to that of the`RedisLockStore` which begins at 0.  
If the ticket expires, the ticket number will not be reassigned to future tickets, as a result ticket numbers are unique to ticket instances.  
Ticket numbers are incremented using the Redis atomic transaction INCR on the persisted last issued ticket number.

The `ConcurrentRedisLockStore` ensures that only one Rasa instance can handle a conversation at any point in time.  
Therefore, this Redis implementation of the `LockStore` can handle messages received in parallel for the same conversation by different Rasa servers.  
This is the recommended lock store for running a replicated set of Rasa servers.

### High Availability Support  
New in 3.14

Redis high availability support is now available for the `ConcurrentRedisLockStore`.  
You can now deploy with Redis Cluster for horizontal scaling or Redis Sentinel for automatic failover.

The `ConcurrentRedisLockStore` now supports Redis high availability deployments through Redis Cluster and Redis Sentinel modes, enabling enterprise-grade scalability and reliability for production deployments.  
The supported deployments are:

- Redis Cluster Mode: Provides horizontal scaling and is compatible with cloud-hosted Redis services.
- Redis Sentinel Mode: Offers high availability through automatic master/slave failover.
- Standard Mode: Maintains backward compatibility with existing single-instance deployments.

### Configuration  
To set up Rasa with Redis, the following steps are required:

1. Add required configuration to your `endpoints.yml`:

```yaml
  lock_store:
      type: rasa_plus.components.concurrent_lock_store.ConcurrentRedisLockStore
      host: "host of the redis instance, e.g. localhost/"
      port: "port of your redis instance, usually 6379/"
      password: "password used for authentication"
      db: "number of your database within redis, e.g. 0. Not used in cluster mode"
      key_prefix: "alphanumeric value to prepend to lock store keys"
      # high availability parameters introduced in 3.14 below
      deployment_mode: "standard, cluster, or sentinel"
      endpoints: "list of redis cluster/sentinel node addresses in the format host:port"
      sentinel_service: "name of the redis sentinel service, only used in sentinel mode"
```

```yaml
  lock_store:
      type: concurrent_redis
      host: "host of the redis instance, e.g. localhost"
      port: "port of your redis instance, usually 6379"
      password: "password used for authentication"
      db: "number of your database within redis, e.g. 0. Not used in cluster mode"
      key_prefix: "alphanumeric value to prepend to lock store keys"
      # high availability parameters introduced in 3.14 below
      deployment_mode: "standard, cluster, or sentinel"
      endpoints: "list of redis cluster/sentinel node addresses in the format host:port"
      sentinel_service: "name of the redis sentinel service, only used in sentinel mode"
```

2. To start the Rasa server using your Redis backend, add the `--endpoints` flag, e.g.:

```bash
rasa run -m models --endpoints endpoints.yml
```

### Configuration Parameters

- `url` (default: `localhost`): The url of your redis instance
- `port` (default: `6379`): The port which redis is running on
- `db` (default: `1`): The number of your redis database. _Ignored in cluster mode as Redis Cluster always uses database 0_
- `key_prefix` (default: `None`): The prefix to prepend to lock store keys. Must be alphanumeric
- `password` (default: `None`): Password used for authentication (`None` equals no authentication)
- `use_ssl` (default: `False`): Whether the communication is encrypted
- `socket_timeout` (default: `10`): Time in seconds after which an error is raised if Redis doesn't answer
- `deployment_mode` (default: `standard`): Deployment mode of Redis. One of `standard`, `cluster`, or `sentinel`.
- `endpoints` (default: `None`): List of Redis cluster node addresses in the format `host:port`. Used for cluster and sentinel modes.
- `sentinel_service` (default: `mymaster`): Name of the Redis sentinel service. Only used in sentinel mode.

#### Deployment Mode Details

- Standard Mode: Connects to a single Redis instance using url and port parameters.
- Cluster Mode: Connects to a Redis Cluster for horizontal scaling. If endpoints is not provided, falls back to auto-discovery using url and port.
- Sentinel Mode: Connects to Redis Sentinel for high availability with automatic master/slave failover.

### Choosing a Deployment Mode

- Use standard mode for simple deployments with a single Redis instance.
- Use cluster mode for horizontal scaling and when using cloud Redis services that require cluster mode.
- Use sentinel mode for high availability with master/slave replication and automatic failover.

### Using IAM roles to authenticate to AWS ElastiCache for Redis
New in 3.14

You can use IAM authentication to connect to AWS ElastiCache for Redis without needing to provide static credentials.
If your Rasa instance is running on an AWS service that supports IAM roles (e.g. EC2), you can  use IAM authentication to connect to AWS ElastiCache for Redis without needing to provide static credentials.  
To do so, you need to ensure that your AWS ElastiCache cluster or replication group is configured to allow IAM authentication by creating an AWS ElastiCache user with IAM authentication mode enabled.

You also need to set up your Rasa instance with an appropriate IAM role that has the permissions to access the AWS ElastiCache cluster or replication group:

```json
{
    "Version": "2012-10-17",
    "Statement": [\
        {\
            "Effect": "Allow",\
            "Action": [\
                "elasticache:Connect"\
            ],\
            "Resource": "*"\
        }\
    ]
}
```

Once you have set up the IAM role and configured your ElastiCache cluster or replication group, you can configure the following environment variables in your Rasa instance:

- `IAM_CLOUD_PROVIDER`: Set this to `aws`.
- `AWS_DEFAULT_REGION`: Set this to the AWS region where your ElastiCache cluster or replication group is located.
- `AWS_ELASTICACHE_CLUSTER_NAME`: Set this to the name of your ElastiCache cluster or replication group.
- `ELASTICACHE_REDIS_AWS_IAM_ENABLED`: Set this to `true` to enable IAM authentication for ElastiCache Redis connections.

You can configure the lock store in your `endpoints.yml` file to not use a username and password:

```yaml
lock_store:
    type: concurrent_redis
    host: "master redis host of your elasticache cluster or replication group"
    port: "6379"
    use_ssl: true
    username: your-iam-username
    ssl_ca_certs: "/path/to/your/ca-certificate.pem" # Optional, path to the root certificate from Amazon Trust Services
```

When you start your Rasa instance, it will use the IAM role to generate temporary credentials to log in to the AWS ElastiCache cluster instead of using static credentials. The temporary credentials will be automatically refreshed every 15 minutes.

### Migration Guide
To switch from the `RedisLockStore` to the `ConcurrentRedisLockStore`, specify the complete module path to the `ConcurrentRedisLockStore` class as `type` in `endpoints.yml`:

```yaml
lock_store:
    type: rasa_plus.components.concurrent_lock_store.ConcurrentRedisLockStore
    host: "host of the redis instance, e.g. localhost"
    port: "port of your redis instance, usually 6379"
    password: "password used for authentication"
    db: "number of your database within redis, e.g. 0. Not used in cluster mode"
    key_prefix: "alphanumeric value to prepend to lock store keys"
    # high availability parameters introduced in 3.14 below
    deployment_mode: <standard, cluster, or sentinel>
    endpoints: <list of redis cluster/sentinel node addresses in the format host:port>
    sentinel_service: <name of the redis sentinel service, only used in sentinel mode>
```

You must replace the `url` field in the redis lock store configuration with a field `host` containing the hostname of the redis instance.
No database migration is required when switching to the `ConcurrentRedisLockStore`. You can use the same Redis instance and database number as you did previously when using the `RedisLockStore`.  
You may want to delete all the preexisting keys if using the same Redis database number.  
These former key-value items are no longer required by the `ConcurrentRedisLockStore` and the database can be cleared.

There is no overlap in key-value items stored when using the `RedisLockStore` and the `ConcurrentRedisLockStore`, because the `RedisLockStore` persists serialized [TicketLock](https://legacy-docs-oss.rasa.com/docs/rasa/reference/rasa/core/lock/#ticketlock-objects) instances while the `ConcurrentRedisLockStore` instead stores individual [`Ticket`](https://legacy-docs-oss.rasa.com/docs/rasa/reference/rasa/core/lock/#ticket-objects) instances, as well as the last issued ticket number.

The `ConcurrentRedisLockStore` recreates the `TicketLock` from the persisted `Ticket` instances, which allows it to handle concurrent messages for the same conversation ID.

## RedisLockStore

### Description
`RedisLockStore` maintains conversation locks using Redis as a persistence layer.

### High Availability Support
New in 3.14  
Redis high availability support is now available for the `RedisLockStore`.  
You can now deploy with Redis Cluster for horizontal scaling or Redis Sentinel for automatic failover.

The `RedisLockStore` now supports Redis high availability deployments through Redis Cluster and Redis Sentinel modes, enabling enterprise-grade scalability and reliability for production deployments.  
The supported deployments are:

### Configuration
To set up Rasa with Redis, the following steps are required:

1. Add required configuration to your `endpoints.yml`

```yaml
lock_store:
       type: "redis"
       url: <url of the redis instance, e.g. localhost>
       port: <port of your redis instance, usually 6379>
       password: <password used for authentication>
       db: <number of your database within redis, e.g. 0. Not used in cluster mode>
       key_prefix: <alphanumeric value to prepend to lock store keys>
       # high availability parameters introduced in 3.14 below
       deployment_mode: <standard, cluster, or sentinel>
       endpoints: <list of redis cluster/sentinel node addresses in the format host:port>
       sentinel_service: <name of the redis sentinel service, only used in sentinel mode>
```

2. To start the Rasa server using your Redis backend, add the `--endpoints` flag, e.g.:

```bash
rasa run -m models --endpoints endpoints.yml
```

### Configuration Parameters
- `url` (default: `localhost`): The url of your redis instance
- `port` (default: `6379`): The port which redis is running on
- `db` (default: `1`): The number of your redis database. _Ignored in cluster mode as Redis Cluster always uses database 0_
- `key_prefix` (default: `None`): The prefix to prepend to lock store keys. Must be alphanumeric
- `username` (default: `None`): Username used for authentication
- `password` (default: `None`): Password used for authentication (`None` equals no authentication)
- `use_ssl` (default: `False`): Whether or not the communication is encrypted
- `ssl_keyfile` (default: `None`): Path to an ssl private key
- `ssl_certfile` (default: `None`): Path to an ssl certificate
- `ssl_ca_certs` (default: `None`): The path to a file of concatenated CA certificates in PEM format
- `socket_timeout` (default: `10`): Time in seconds after which an error is raised if Redis doesn't answer
- `deployment_mode` (default: `standard`): Deployment mode of Redis. One of `standard`, `cluster`, or `sentinel`.
- `endpoints` (default: `None`): List of Redis cluster node addresses in the format `host:port`. Used for cluster and sentinel modes.
- `sentinel_service` (default: `mymaster`): Name of the Redis sentinel service. Only used in sentinel mode.

#### Deployment Mode Details
- Standard Mode: Connects to a single Redis instance using url and port parameters.
- Cluster Mode: Connects to a Redis Cluster for horizontal scaling. If endpoints is not provided, falls back to auto-discovery using url and port.
- Sentinel Mode: Connects to Redis Sentinel for high availability with automatic master/slave failover.

### Choosing a Deployment Mode
- Use standard mode for simple deployments with a single Redis instance.
- Use cluster mode for horizontal scaling and when using cloud Redis services that require cluster mode.
- Use sentinel mode for high availability with master/slave replication and automatic failover.

### Using IAM roles to authenticate to AWS ElastiCache (for Redis)
New in 3.14

You can use IAM authentication to connect to AWS ElastiCache for Redis without needing to provide static credentials.
