def __init__(self): # first choose a node randomly poll = RedisClientPool.get_pool() node_names = poll.names self._node_ = random.choice(node_names) self.client = poll.get_client(self._node_) # then pick a random address for the object self._addr_ = self.get_a_valid_redis_addr() self.initialize()
def _from_addr(cls, addr): obj = cls.__new__(cls) obj._addr_ = addr obj._node_ = cls.get_node_from_addr(addr) obj.client = RedisClientPool.get_pool().get_client(obj._node_) obj.initialize() # when instantiate a redis object from address, increment the counter obj._incr_refcnt() return obj
def test(): # Configure the client pool singleton instance RedisClientPool.get_pool().load_config({"redis1": {"host":"127.0.0.1", "port": 6379, "db":0}})