當前位置: 首頁>>代碼示例>>Python>>正文


Python Talker.talk_raw方法代碼示例

本文整理匯總了Python中clusternode.Talker.talk_raw方法的典型用法代碼示例。如果您正苦於以下問題:Python Talker.talk_raw方法的具體用法?Python Talker.talk_raw怎麽用?Python Talker.talk_raw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在clusternode.Talker的用法示例。


在下文中一共展示了Talker.talk_raw方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fix_migrating

# 需要導入模塊: from clusternode import Talker [as 別名]
# 或者: from clusternode.Talker import talk_raw [as 別名]
def fix_migrating(host, port):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Talker(host, port)
    try:
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug("Ask `cluster nodes` Rsp %s", m)
        for node_info in m.split("\n"):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(" "))
            node.host = node.host or host
            nodes[node.node_id] = node

            mig_dsts.extend([(node, {"slot": g[0], "id": g[1]}) for g in PAT_MIGRATING_IN.findall(node_info)])
            mig_srcs.extend([(node, {"slot": g[0], "id": g[1]}) for g in PAT_MIGRATING_OUT.findall(node_info)])

        for n, args in mig_dsts:
            node_id = args["id"]
            if node_id not in nodes:
                logging.error(
                    "Fail to fix %s:%d <- (referenced from %s:%d)" " - node %s is missing",
                    n.host,
                    n.port,
                    host,
                    port,
                    node_id,
                )
                continue
            _migr_one_slot(nodes[node_id], n, int(args["slot"]), nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args["id"]
            if node_id not in nodes:
                logging.error(
                    "Fail to fix %s:%d -> (referenced from %s:%d)" " - node %s is missing",
                    n.host,
                    n.port,
                    host,
                    port,
                    node_id,
                )
                continue
            _migr_one_slot(n, nodes[node_id], int(args["slot"]), nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
開發者ID:yufan2hao,項目名稱:redis-trib.py,代碼行數:50,代碼來源:command.py

示例2: shutdown_cluster

# 需要導入模塊: from clusternode import Talker [as 別名]
# 或者: from clusternode.Talker import talk_raw [as 別名]
def shutdown_cluster(host, port):
    t = Talker(host, port)
    try:
        _ensure_cluster_status_set(t)
        myself = None
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug('Ask `cluster nodes` Rsp %s', m)
        nodes_info = filter(None, m.split('\n'))
        if len(nodes_info) > 1:
            raise RedisStatusError('More than 1 nodes in cluster.')
        try:
            m = t.talk('cluster', 'reset')
        except hiredis.ReplyError, e:
            if 'containing keys' in e.message:
                raise RedisStatusError('Cluster containing keys')
            raise
        logging.debug('Ask `cluster delslots` Rsp %s', m)
開發者ID:dongzerun,項目名稱:redis-trib.py,代碼行數:19,代碼來源:command.py

示例3: fix_migrating

# 需要導入模塊: from clusternode import Talker [as 別名]
# 或者: from clusternode.Talker import talk_raw [as 別名]
def fix_migrating(host, port):
    nodes = dict()
    mig_srcs = []
    mig_dsts = []
    t = Talker(host, port)
    try:
        m = t.talk_raw(CMD_CLUSTER_NODES)
        logging.debug('Ask `cluster nodes` Rsp %s', m)
        for node_info in m.split('\n'):
            if not _valid_node_info(node_info):
                continue
            node = ClusterNode(*node_info.split(' '))
            node.host = node.host or host
            nodes[node.node_id] = node

            search = PAT_MIGRATING_IN.search(node_info)
            if search is not None:
                mig_dsts.append((node, search.groupdict()))

            search = PAT_MIGRATING_OUT.search(node_info)
            if search is not None:
                mig_srcs.append((node, search.groupdict()))

        for n, args in mig_dsts:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d <- (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(nodes[node_id], n, int(args['slot']),
                           nodes.itervalues())
        for n, args in mig_srcs:
            node_id = args['id']
            if node_id not in nodes:
                logging.error('Fail to fix %s:%d -> (referenced from %s:%d)'
                              ' - node %s is missing', n.host, n.port,
                              host, port, node_id)
                continue
            _migr_one_slot(n, nodes[node_id], int(args['slot']),
                           nodes.itervalues())
    finally:
        t.close()
        for n in nodes.itervalues():
            n.close()
開發者ID:marswon,項目名稱:redis-trib.py,代碼行數:47,代碼來源:command.py

示例4: join_cluster

# 需要導入模塊: from clusternode import Talker [as 別名]
# 或者: from clusternode.Talker import talk_raw [as 別名]
def join_cluster(cluster_host, cluster_port, newin_host, newin_port,
                 balancer=None, balance_plan=base_balance_plan):
    nodes = []
    t = Talker(newin_host, newin_port)
    try:
        _join_to_cluster(cluster_host, cluster_port, t)
        logging.info('Instance at %s:%d has joined %s:%d; now balancing slots',
                     newin_host, newin_port, cluster_host, cluster_port)

        m = t.talk_raw(CMD_CLUSTER_INFO)
        logging.debug('Ask `cluster info` Rsp %s', m)
        cluster_state = PAT_CLUSTER_STATE.findall(m)
        if cluster_state[0] != 'ok':
            raise hiredis.ProtocolError(
                'Node %s:%d is already in a cluster' % (t.host, t.port))
        slots = int(PAT_CLUSTER_SLOT_ASSIGNED.findall(m)[0])
        nodes = _list_nodes(t, default_host=newin_host)[0]

        for source, target, count in balance_plan(nodes, balancer):
            _migr_slots(source, target, count, nodes)
    finally:
        t.close()
        for n in nodes:
            n.close()
開發者ID:dongzerun,項目名稱:redis-trib.py,代碼行數:26,代碼來源:command.py


注:本文中的clusternode.Talker.talk_raw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。