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
1import launchflow as lf
2
3# Automatically creates / connects to a Memorystore Redis cluster in your GCP project
4memorystore = lf.gcp.MemorystoreRedis("my-redis-cluster")
5
6# Set a key-value pair
7client = memorystore.redis()
8client.set("my-key", "my-value")
9
10# Async compatible
11async_client = await memorystore.redis_async()
12await 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
1MemorystoreRedis.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
1MemorystoreRedis.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 MemorystoreRedis.redis_async()
Get an Async Redis Client object from the redis-py library.
Returns:
- The Async Redis Client object from the redis-py library.