launchflow.gcp.memorystore

MemorystoreRedis

1
class MemorystoreRedis(GCPResource[MemorystoreRedisConnectionInfo])

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

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
memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
4
5
# Set a key-value pair
6
client = memorystore.redis()
7
client.set("my-key", "my-value")
8
9
# Async compatible
10
async_client = await memorystore.redis_async()
11
await async_client.set("my-key", "my-value")

__init__

1
def __init__(name: str, *, memory_size_gb: int = 1) -> None

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
def 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
def redis()

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

Returns:

redis_async

1
async def redis_async()

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

Returns: