How to use the hiredis.ProtocolError function in hiredis

To help you get started, we’ve selected a few hiredis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github projecteru / redis-ctl / redisctl / communicate.py View on Github external
m = t.talk_raw(CMD_INFO)
    cluster_enabled = PAT_CLUSTER_ENABLED.findall(m)
    if len(cluster_enabled) == 0 or int(cluster_enabled[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not cluster enabled' % (t.host, t.port))

    m = t.talk_raw(CMD_CLUSTER_NODES)
    if len(filter(None, m.split('\n'))) != 1:
        raise hiredis.ProtocolError(
            'Node %s:%d is already in a cluster' % (t.host, t.port))

    m = t.talk_raw(CMD_CLUSTER_INFO)
    cluster_state = PAT_CLUSTER_STATE.findall(m)
    cluster_slot_assigned = PAT_CLUSTER_SLOT_ASSIGNED.findall(m)
    if cluster_state[0] != 'fail' or int(cluster_slot_assigned[0]) != 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is already in a cluster' % (t.host, t.port))
github projecteru / redis-ctl / daemonutils / bgtask.py View on Github external
def _quit(_, cluster_id, host, port):
    try:
        me = redistrib.command.list_nodes(host, port, host)[1]
        if len(me.assigned_slots) != 0:
            raise ValueError('node still holding slots')
        redistrib.command.quit_cluster(host, port)
    except SocketError, e:
        logging.exception(e)
        logging.info('Remove instance from cluster on exception')
    except ProtocolError, e:
        if NOT_IN_CLUSTER_MESSAGE not in e.message:
            raise

    remove_empty_cluster(cluster_id)
    n = get_node_by_host_port(host, port)
    if n is not None:
        n.assignee_id = None
        db.session.add(n)
    commit_session()
    return True
github projecteru / redis-trib.py / redistrib / command.py View on Github external
def _ensure_cluster_status_set(t):
    m = t.send_raw(CMD_INFO)
    logging.debug('Ask `info` Rsp %s', m)
    cluster_enabled = PAT_CLUSTER_ENABLED.findall(m)
    if len(cluster_enabled) == 0 or int(cluster_enabled[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not cluster enabled' % (t.host, t.port))

    m = t.send_raw(CMD_CLUSTER_INFO)
    logging.debug('Ask `cluster info` Rsp %s', m)
    cluster_state = PAT_CLUSTER_STATE.findall(m)
    cluster_slot_assigned = PAT_CLUSTER_SLOT_ASSIGNED.findall(m)
    if cluster_state[0] != 'ok' and int(cluster_slot_assigned[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not in a cluster' % (t.host, t.port))
github projecteru / redis-trib.py / redistrib / command.py View on Github external
def _ensure_cluster_status_unset(t):
    m = t.send_raw(CMD_INFO)
    logging.debug('Ask `info` Rsp %s', m)
    cluster_enabled = PAT_CLUSTER_ENABLED.findall(m)
    if len(cluster_enabled) == 0 or int(cluster_enabled[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not cluster enabled' % (t.host, t.port))

    m = t.send_raw(CMD_CLUSTER_INFO)
    logging.debug('Ask `cluster info` Rsp %s', m)
    cluster_state = PAT_CLUSTER_STATE.findall(m)
    cluster_slot_assigned = PAT_CLUSTER_SLOT_ASSIGNED.findall(m)
    if cluster_state[0] != 'fail' or int(cluster_slot_assigned[0]) != 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is already in a cluster' % (t.host, t.port))
github thefab / tornadis / tornadis / client.py View on Github external
if data is not None:
                self.__reader.feed(data)
                while True:
                    reply = self.__reader.gets()
                    if reply is not False:
                        try:
                            callback = self.__callback_queue.popleft()
                            # normal client (1 reply = 1 callback)
                            callback(reply)
                        except IndexError:
                            # pubsub clients
                            self._reply_list.append(reply)
                            self._condition.notify_all()
                    else:
                        break
        except hiredis.ProtocolError:
            # something nasty occured (corrupt stream => no way to recover)
            LOG.warning("corrupted stream => disconnect")
            self.disconnect()
github projecteru / redis-trib.py / redistrib / command.py View on Github external
def _ensure_cluster_status_set(t):
    m = t.send_raw(CMD_INFO)
    logging.debug('Ask `info` Rsp %s', m)
    cluster_enabled = PAT_CLUSTER_ENABLED.findall(m)
    if len(cluster_enabled) == 0 or int(cluster_enabled[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not cluster enabled' % (t.host, t.port))

    m = t.send_raw(CMD_CLUSTER_INFO)
    logging.debug('Ask `cluster info` Rsp %s', m)
    cluster_state = PAT_CLUSTER_STATE.findall(m)
    cluster_slot_assigned = PAT_CLUSTER_SLOT_ASSIGNED.findall(m)
    if cluster_state[0] != 'ok' and int(cluster_slot_assigned[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not in a cluster' % (t.host, t.port))
github jplesperance / redis-sniffer / redis_sniffer / sniffer.py View on Github external
def process_request_packet(self, length, data):
        self.request_size += length
        self.req_reader.feed(data)

        try:
            command = self.req_reader.gets()
            # command will be False or an array of tokens that describe the command
            while command is not False:
                self.commands.append(' '.join(command))
                command = self.req_reader.gets()
        except hiredis.ProtocolError:
            logging.debug('Partial command')

hiredis

Python wrapper for hiredis

MIT
Latest version published 8 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages