A1: Sim, eles usam o mesmo pool de conexões.
A2: Isso não é uma boa prática, pois você não pode controlar a inicialização dessa instância. Uma alternativa seria usar singleton.
import redis class Singleton(type): """ An metaclass for singleton purpose. Every singleton class should inherit from this class by 'metaclass=Singleton'. """ _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls._instances: cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls] class RedisClient(object): def __init__(self): self.pool = redis.ConnectionPool(host = HOST, port = PORT, password = PASSWORD) @property def conn(self): if not hasattr(self, '_conn'): self.getConnection() return self._conn def getConnection(self): self._conn = redis.Redis(connection_pool = self.pool) Assim, RedisClient será uma classe singleton. Não importa quantas vezes você chame client = RedisClient(), você obterá o mesmo objeto.
Então você pode usá-lo assim:
from RedisClient import RedisClient client = RedisClient() species = 'lion' key = 'zoo:{0}'.format(species) data = client.conn.hmget(key, 'age', 'weight') print(data) E a primeira vez que você chamar client = RedisClient() será quando a instância for realmente inicializada.
Ou você pode querer obter uma instância diferente com base em argumentos distintos:
class Singleton(type): """ An metaclass for singleton purpose. Every singleton class should inherit from this class by 'metaclass=Singleton'. """ _instances = {} def __call__(cls, *args, **kwargs): key = (args, tuple(sorted(kwargs.items()))) if cls not in cls._instances: cls._instances[cls] = {} if key not in cls._instances[cls]: cls._instances[cls][key] = super(Singleton, cls).__call__(*args, **kwargs) return cls._instances[cls][key]