当前位置: 首页>>代码示例>>Python>>正文


Python StrictRedisCluster.ping方法代码示例

本文整理汇总了Python中rediscluster.StrictRedisCluster.ping方法的典型用法代码示例。如果您正苦于以下问题:Python StrictRedisCluster.ping方法的具体用法?Python StrictRedisCluster.ping怎么用?Python StrictRedisCluster.ping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rediscluster.StrictRedisCluster的用法示例。


在下文中一共展示了StrictRedisCluster.ping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_refresh_using_specific_nodes

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import ping [as 别名]
def test_refresh_using_specific_nodes(r):
    """
    Test making calls on specific nodes when the cluster has failed over to
    another node
    """
    with patch.object(StrictRedisCluster, 'parse_response') as parse_response_mock:
        with patch.object(NodeManager, 'initialize', autospec=True) as init_mock:
            # simulate 7006 as a failed node
            def side_effect(self, *args, **kwargs):
                if self.port == 7006:
                    parse_response_mock.failed_calls += 1
                    raise ClusterDownError('CLUSTERDOWN The cluster is down. Use CLUSTER INFO for more information')
                elif self.port == 7007:
                    parse_response_mock.successful_calls += 1

            def side_effect_rebuild_slots_cache(self):
                # start with all slots mapped to 7006
                self.nodes = {'127.0.0.1:7006': {'host': '127.0.0.1', 'server_type': 'master', 'port': 7006, 'name': '127.0.0.1:7006'}}
                self.slots = {}

                for i in range(0, 16383):
                    self.slots[i] = [{
                        'host': '127.0.0.1',
                        'server_type': 'master',
                        'port': 7006,
                        'name': '127.0.0.1:7006',
                    }]

                # After the first connection fails, a reinitialize should follow the cluster to 7007
                def map_7007(self):
                    self.nodes = {'127.0.0.1:7007': {'host': '127.0.0.1', 'server_type': 'master', 'port': 7007, 'name': '127.0.0.1:7007'}}
                    self.slots = {}

                    for i in range(0, 16383):
                        self.slots[i] = [{
                            'host': '127.0.0.1',
                            'server_type': 'master',
                            'port': 7007,
                            'name': '127.0.0.1:7007',
                        }]
                init_mock.side_effect = map_7007

            parse_response_mock.side_effect = side_effect
            parse_response_mock.successful_calls = 0
            parse_response_mock.failed_calls = 0

            init_mock.side_effect = side_effect_rebuild_slots_cache

            rc = StrictRedisCluster(host='127.0.0.1', port=7006)
            assert len(rc.connection_pool.nodes.nodes) == 1
            assert '127.0.0.1:7006' in rc.connection_pool.nodes.nodes

            rc.ping()

            # Cluster should now point to 7006, and there should be one failed and one succesful call
            assert len(rc.connection_pool.nodes.nodes) == 1
            assert '127.0.0.1:7007' in rc.connection_pool.nodes.nodes
            assert parse_response_mock.failed_calls == 1
            assert parse_response_mock.successful_calls == 1
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:61,代码来源:test_cluster_obj.py


注:本文中的rediscluster.StrictRedisCluster.ping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。