Avoid creating many redis connections when you want to have seperate buckets of templates.
Ankcorn opened this issue · comments
Currently when using drain3 with redis you have to configure a redis_key. This key can be a useful way to seperate data and make Drain3 useful in a multi tenant situation where you might not want templates to be shared.
i.e. Setting up the template miner with redis persistence.
persistance = RedisPersistence(
redis_host=self.redis_config.redis_host,
redis_port=self.redis_config.redis_port,
redis_db=self.redis_config.redis_db,
redis_pass=self.redis_config.redis_pass,
is_ssl=self.redis_config.is_ssl,
redis_key=self.get_key(workspace, environment)
)
template_miner = TemplateMiner(persistance, config=self.config)
This code creates a redis connection when you instantiate RedisPersistance, this means that with many tenants you can have issues with too many connections.
It would be desirable for RedisPersistance to take an optional property of redis.Redis so that multiple connections are not made.
i.e. Create Redis connection and pass it in to RedisPersistence
import redis
redis_connection = redis.Redis(...)
persistance = RedisPersistence(
redis= redis_connection
redis_key=self.get_key(workspace, environment)
)
template_miner = TemplateMiner(persistance, config=self.config)
Hi, thanks for the issue, would you like to open a pull request?
Hi, yes I will make a PR 😄