# MemoryDB

Source: /aws/services/memorydb/

## Introduction

Amazon MemoryDB is a fully managed, in-memory database service designed for ultra-fast, primary database use cases. Compatible with both Valkey and Redis OSS, it improves performance and durability.

Built for the AWS cloud environment, MemoryDB simplifies the deployment and operation of in-memory databases, acting as a replacement for using a cache in front of a database. 

LocalStack provides support for the main MemoryDB APIs surrounding cluster creation, allowing developers to utilize the MemoryDB functionalities in their local development environment.
The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of MemoryDB's integration with LocalStack.

## Getting started

This guide is designed for users new to MemoryDB and assumes basic knowledge of the AWS CLI and our [`lstk aws`](/aws/developer-tools/running-localstack/lstk/cloud-and-iac-commands/#aws) command.

Start your LocalStack container using your preferred method.
We will demonstrate how you can create a MemoryDB cluster and connect to it.

### Basic cluster creation

You can create a MemoryDB cluster using the [`CreateCluster`](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_CreateCluster.html) API.
Run the following command to create a cluster:

```bash
lstk aws memorydb create-cluster \
  --cluster-name my-redis-cluster \
  --node-type db.t4g.small \
  --acl-name open-access
```

Once it becomes available, you will be able to use the cluster endpoint for Redis operations.
Run the following command to retrieve the cluster endpoint using the [`DescribeClusters`](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_DescribeClusters.html) API:

```bash
lstk aws memorydb describe-clusters --query "Clusters[0].ClusterEndpoint"
```

```bash title="Output"
{
  "Address": "127.0.0.1",
  "Port": 36739
}
```

The cache cluster uses a random port of the [external service port range](/aws/customization/networking/external-port-range/) in regular execution and a port between 36739 and 46738 in container mode.
Use this port number to connect to the Redis instance using the `redis-cli` command line tool:

```bash
redis-cli -p 4510 ping
PONG
redis-cli -p 4510 set foo bar
OK
redis-cli -p 4510 get foo
"bar"
```

You can also check the cluster configuration using the [`cluster nodes`](https://redis.io/commands/cluster-nodes) command:

```bash
redis-cli -c -p 4510 cluster nodes
```

## Container mode

To start Redis clusters of a specific version, enable container mode for Redis-based services in LocalStack.
This approach directs LocalStack to launch Redis instances in distinct containers, utilizing your chosen image tag.
Additionally, container mode is beneficial for independently examining the logs of each Redis instance.
To activate this, set the `REDIS_CONTAINER_MODE` configuration variable to `1`.


## Valkey Engine 

LocalStack offers the additional option to use Valkey as an alternative to Redis in Amazon MemoryDB. 

To enable full Valkey emulation: 

1. Start LocalStack with Valkey support enabled by setting the environment variable, `REDIS_CONTAINER_MODE=1`
2. Create a cluster with the Valkey engine by including the `--engine valkey` flag in your API call:

```bash
lstk aws memorydb create-cluster \
  --cluster-name my-valkey-cluster \
  --node-type db.t4g.small \
  --acl-name open-access \
  --engine valkey
```

Valkey support includes:

- The ability to specify `valkey` as the engine when creating Amazon MemoryDB clusters.

- Automatic mapping of each engine to a default supported version (Redis `7.2.10`, Valkey `7.2.10`), ensuring DockerHub compatibility.

- Support for the `Engine` and `EngineVersion` fields in the `CreateCluster` API, which now recognize and handle `valkey`.

:::note
A Valkey cluster can only be started when [container mode](/aws/services/memorydb/#container-mode) is enabled. 
::: 

## Current Limitations

LocalStack's emulation support for MemoryDB primarily focuses on the creation and termination of Redis servers in cluster mode.

Essential resources for running a cluster, such as parameter groups, security groups, and subnet groups, are mocked but have no effect on the Redis servers' operation.

LocalStack currently doesn't support MemoryDB snapshots, failovers, users/passwords, service updates, replication scaling, SSL, migrations, service integration (like CloudWatch/Kinesis log delivery, SNS notifications) or tests.

At present, LocalStack does not support features such as:

- MemoryDB snapshots
- Failovers
- User/password management
- Service updates
- Replication scaling
- SSL
- Migrations
- Service integration (e.g., CloudWatch/Kinesis log delivery, SNS notifications) or facilitate related testing.

## API Coverage


### MemoryDB for Redis API coverage

Source service: `memorydb`. 15 of 45 tracked operations are implemented.

Service documentation: /aws/services/memorydb/
License availability: available starting with the Ultimate plan. See /aws/licensing/ for current plan details.

| Operation | Status |
| --- | --- |
| BatchUpdateCluster | Not implemented |
| CopySnapshot | Not implemented |
| CreateACL | Implemented |
| CreateCluster | Implemented |
| CreateMultiRegionCluster | Not implemented |
| CreateParameterGroup | Not implemented |
| CreateSnapshot | Not implemented |
| CreateSubnetGroup | Implemented |
| CreateUser | Not implemented |
| DeleteACL | Implemented |
| DeleteCluster | Implemented |
| DeleteMultiRegionCluster | Not implemented |
| DeleteParameterGroup | Not implemented |
| DeleteSnapshot | Not implemented |
| DeleteSubnetGroup | Implemented |
| DeleteUser | Not implemented |
| DescribeACLs | Implemented |
| DescribeClusters | Implemented |
| DescribeEngineVersions | Not implemented |
| DescribeEvents | Not implemented |
| DescribeMultiRegionClusters | Not implemented |
| DescribeMultiRegionParameterGroups | Not implemented |
| DescribeMultiRegionParameters | Not implemented |
| DescribeParameterGroups | Not implemented |
| DescribeParameters | Not implemented |
| DescribeReservedNodes | Not implemented |
| DescribeReservedNodesOfferings | Not implemented |
| DescribeServiceUpdates | Not implemented |
| DescribeSnapshots | Not implemented |
| DescribeSubnetGroups | Implemented |
| DescribeUsers | Not implemented |
| FailoverShard | Not implemented |
| ListAllowedMultiRegionClusterUpdates | Not implemented |
| ListAllowedNodeTypeUpdates | Not implemented |
| ListTags | Implemented |
| PurchaseReservedNodesOffering | Not implemented |
| ResetParameterGroup | Not implemented |
| TagResource | Implemented |
| UntagResource | Implemented |
| UpdateACL | Implemented |
| UpdateCluster | Implemented |
| UpdateMultiRegionCluster | Not implemented |
| UpdateParameterGroup | Not implemented |
| UpdateSubnetGroup | Implemented |
| UpdateUser | Not implemented |
