By default, each Redis
instance
you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool
instance to the connection_pool
argument of the Redis class.
Example :
class RedisConnection:
def __new__(cls):
if not hasattr(cls, 'instance'):
pool = redis.ConnectionPool(host='******', password='*****', port=*****, db=0)
cls.instance = redis.Redis(connection_pool=pool)
return cls.instance
obj_1=RedisConnection()
print(id(obj_1))
obj_2=RedisConnection()
print(id(obj_2))
redis
connectionpooling
python