MemorystoreRedis

A Redis cluster running on Google Cloud's Memorystore service.

Like all Resources, this class configures itself across multiple Environments.

For more information see the official documentation.

NOTE: This resource can only be accessed from within the same VPC it is created in. Use ComputeEngineRedis to create a Redis instance that can be accessed from outside the VPC.

Example Usage

1
import launchflow as lf
2
3
# Automatically creates / connects to a Memorystore Redis cluster in your GCP project
4
memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
5
6
# Set a key-value pair
7
client = memorystore.redis()
8
client.set("my-key", "my-value")
9
10
# Async compatible
11
async_client = await memorystore.redis_async()
12
await async_client.set("my-key", "my-value")

initialization

Create a new Memorystore Redis resource.

Args:

  • name (str): The name of the Redis VM resource. This must be globally unique.
  • memory_size_gb (int): The memory size of the Redis instance in GB. Defaults to 1.

django_settings

1
MemorystoreRedis.django_settings()

Returns a Django settings dictionary for connecting to the Memorystore Redis cluster.

Example usage:

1
import launchflow as lf
2
3
memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
4
5
# settings.py
6
CACHES = {
7
# Connect Django's cache backend to the Memorystore Redis cluster
8
"default": memorystore.django_settings(),
9
}

redis

1
MemorystoreRedis.redis()

Get a Generic Redis Client object from the redis-py library.

Returns:

redis_async

1
async MemorystoreRedis.redis_async()

Get an Async Redis Client object from the redis-py library.

Returns: