ElasticacheRedis
A Redis cluster running on AWS's Elasticache 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 EC2Redis 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 an Elasticache Redis cluster in your AWS account
4elasticache = lf.aws.ElasticacheRedis("my-redis-cluster")
5
6# Set a key-value pair
7client = elasticache.redis()
8client.set("my-key", "my-value")
9
10# Async compatible
11async_client = await elasticache.redis_async()
12await async_client.set("my-key", "my-value")
initialization
Create a new Elasticache Redis resource.
Args:
name (str)
: The name of the Elasticache Redis cluster.node_type (Optional[str])
: The instance class of the Elasticache Redis cluster. Defaults tocache.t4g.micro
for development environments andcache.r7g.large
for production environments.parameter_group_name (str)
: The name of the parameter group to associate with the Elasticache Redis cluster. Defaults todefault.redis7
.engine_version (str)
: Version number of the cache engine to use. Defaults to7.0
.
inputs
1ElasticacheRedis.inputs(environment_state: EnvironmentState) -> ElasticacheRedisInputs
Get the inputs for the Elasticache Redis resource.
Args:
environment_state (EnvironmentState)
: The environment to get inputs for.
Returns:
ElasticacheRedisInputs
: The inputs for the Elasticache Redis resource.
django_settings
1ElasticacheRedis.django_settings()
Returns a Django settings dictionary for connecting to the Elasticache Redis cluster.
Returns:
- A dictionary of Django settings for connecting to the Elasticache Redis cluster.
Example usage:
1import launchflow as lf
2
3elasticache = lf.aws.ElasticacheRedis("my-redis-cluster")
4
5# settings.py
6CACHES = {
7 # Connect Django's cache backend to the Elasticache Redis cluster
8 "default": elasticache.django_settings(),
9}
redis
1ElasticacheRedis.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 ElasticacheRedis.redis_async()
Get an Async Redis Client object from the redis-py library.
Returns:
- The Async Redis Client object from the redis-py library.