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


Python StrictRedisCluster.from_url方法代码示例

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


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

示例1: test_access_correct_slave_with_readonly_mode_client

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import from_url [as 别名]
def test_access_correct_slave_with_readonly_mode_client(sr):
    """
    Test that the client can get value normally with readonly mode
    when we connect to correct slave.
    """

    # we assume this key is set on 127.0.0.1:7000(7003)
    sr.set('foo16706', 'foo')
    import time
    time.sleep(1)

    with patch.object(ClusterReadOnlyConnectionPool, 'get_node_by_slot') as return_slave_mock:
        return_slave_mock.return_value = {
            'name': '127.0.0.1:7003',
            'host': '127.0.0.1',
            'port': 7003,
            'server_type': 'slave',
        }

        master_value = {'host': '127.0.0.1', 'name': '127.0.0.1:7000', 'port': 7000, 'server_type': 'master'}
        with patch.object(
                ClusterConnectionPool,
                'get_master_node_by_slot',
                return_value=master_value) as return_master_mock:
            readonly_client = StrictRedisCluster(host="127.0.0.1", port=7000, readonly_mode=True)
            assert b('foo') == readonly_client.get('foo16706')
            assert return_master_mock.call_count == 0

            readonly_client = StrictRedisCluster.from_url(url="redis://127.0.0.1:7000/0", readonly_mode=True)
            assert b('foo') == readonly_client.get('foo16706')
            assert return_master_mock.call_count == 0
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:33,代码来源:test_cluster_obj.py

示例2: StrictRedisCluster

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import from_url [as 别名]
from rediscluster import StrictRedisCluster

startup_nodes = [{"host": "127.0.0.1", "port": "7000"}]

# Note: decode_responses must be set to True when used with python3
rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)
url_client = StrictRedisCluster.from_url('http://127.0.0.1:7000')

__import__('ptpdb').set_trace()
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:11,代码来源:ptp-debug.py


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