当前位置: 首页>>代码示例>>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;未经允许,请勿转载。