async def fetch_cluster_info(self): logger.info('Loading cluster info from {}...'.format(self._nodes)) tasks = [ asyncio.ensure_future( self._get_raw_cluster_info_from_node(node), loop=self._loop ) for node in self._nodes ] try: for task in asyncio.as_completed(tasks, loop=self._loop): try: nodes_raw_response = await task self._cluster_manager = ClusterNodesManager.create( nodes_raw_response) logger.info('Cluster info loaded successfully: %s', list(nodes_raw_response)) return except (ReplyError, ProtocolError, ConnectionError, OSError) as exc: logger.warning( "Loading cluster info from a node failed with {}" .format(repr(exc)) ) finally: for task in tasks: task.cancel() # Wait until all tasks have closed their connection await asyncio.gather( *tasks, loop=self._loop, return_exceptions=True) raise RedisClusterError( "No cluster info could be loaded from any host")
async def fetch_cluster_info(self): logger.info('Loading cluster info from {}...'.format(self._nodes)) tasks = [ asyncio.ensure_future( self._get_raw_cluster_info_from_node(node), loop=self._loop ) for node in self._nodes ] try: for task in asyncio.as_completed(tasks, loop=self._loop): try: nodes_raw_response = list(await task) self._cluster_manager = ClusterNodesManager.create( nodes_raw_response ) logger.info('Cluster info loaded successfully: %s', nodes_raw_response) return except (ReplyError, ProtocolError, ConnectionError, OSError) as exc: logger.warning( "Loading cluster info from a node failed with {}" .format(repr(exc)) ) finally: for task in tasks: task.cancel() # Wait until all tasks have closed their connection await asyncio.gather( *tasks, loop=self._loop, return_exceptions=True) raise RedisClusterError( "No cluster info could be loaded from any host")
def new_execute_redis_con(self, command, *args, encoding=_NOTSET): """Executes redis command and returns Future waiting for the answer. Raises: * TypeError if any of args can not be encoded as bytes. * ReplyError on redis '-ERR' responses. * ProtocolError when response can not be decoded meaning connection is broken. * ConnectionClosedError when either client or server has closed the connection. """ try: command = command.encode() except AttributeError: pass try: command_run = self.__rsm[command.upper()] except KeyError: raise ValueError("You must setup RSM map before execute any command") if self._reader is None or self._reader.at_eof(): msg = self._close_msg or "Connection closed or corrupted" raise ConnectionClosedError(msg) if command is None: raise TypeError("command must not be None") if None in args: raise TypeError("args must not contain None") command = command.upper().strip() is_pubsub = command in _PUBSUB_COMMANDS is_ping = command in ('PING', b'PING') if self._in_pubsub and not (is_pubsub or is_ping): raise RedisError("Connection in SUBSCRIBE mode") elif is_pubsub: logger.warning("Deprecated. Use `execute_pubsub` method directly") return self.execute_pubsub(command, *args) if command in ('SELECT', b'SELECT'): cb = partial(self._set_db, args=args) elif command in ('MULTI', b'MULTI'): cb = self._start_transaction elif command in ('EXEC', b'EXEC'): cb = partial(self._end_transaction, discard=False) encoding = None elif command in ('DISCARD', b'DISCARD'): cb = partial(self._end_transaction, discard=True) else: cb = None if encoding is _NOTSET: encoding = self._encoding command = command_run fut = get_event_loop().create_future() if self._pipeline_buffer is None: self._writer.write(encode_command(command, *args)) else: encode_command(command, *args, buf=self._pipeline_buffer) self._waiters.append((fut, encoding, cb)) return fut
def slaveof(self, host=_NOTSET, port=None): """Make the server a slave of another instance, or promote it as master. Calling slaveof(None) will send ``SLAVEOF NO ONE``. """ if host is _NOTSET: logger.warning("slaveof() form is deprecated!" " Use slaveof(None) to turn redis into a MASTER.") host = None # TODO: drop in 0.3.0 if host is None and port is None: return self._conn.execute(b'SLAVEOF', b'NO', b'ONE') return self._conn.execute(b'SLAVEOF', host, port)
def slaveof(self, host=_NOTSET, port=None): """Make the server a slave of another instance, or promote it as master. Calling ``slaveof(None)`` will send ``SLAVEOF NO ONE``. .. versionchanged:: v0.2.6 ``slaveof()`` form deprecated in favour of explicit ``slaveof(None)``. """ if host is _NOTSET: logger.warning("slaveof() form is deprecated!" " Use slaveof(None) to turn redis into a MASTER.") host = None # TODO: drop in 0.3.0 if host is None and port is None: return self.execute(b'SLAVEOF', b'NO', b'ONE') return self.execute(b'SLAVEOF', host, port)