Drain3 icon indicating copy to clipboard operation
Drain3 copied to clipboard

Avoid creating many redis connections when you want to have seperate buckets of templates.

Open Ankcorn opened this issue 1 year ago • 2 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)

Ankcorn avatar Feb 16 '24 15:02 Ankcorn

Hi, thanks for the issue, would you like to open a pull request?

Superskyyy avatar Feb 19 '24 19:02 Superskyyy

Hi, yes I will make a PR :smile:

Ankcorn avatar Feb 26 '24 11:02 Ankcorn