launchflow.gcp.memorystore
MemorystoreRedis
1class 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:
1import launchflow as lf
2
3memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
4
5# Set a key-value pair
6client = memorystore.redis()
7client.set("my-key", "my-value")
8
9# Async compatible
10async_client = await memorystore.redis_async()
11await async_client.set("my-key", "my-value")
__init__
1def __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
1def django_settings()
Returns a Django settings dictionary for connecting to the Memorystore Redis cluster.
Example usage:
1import launchflow as lf
2
3memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
4
5# settings.py
6CACHES = {
7 # Connect Django's cache backend to the Memorystore Redis cluster
8 "default": memorystore.django_settings(),
9}
redis
1def redis()
Get a Generic Redis Client object from the redis-py library.
Returns:
- The Generic Redis Client from the redis-py library.
redis_async
1async def redis_async()
Get an Async Redis Client object from the redis-py library.
Returns:
- The Async Redis Client object from the redis-py library.