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


Python StrictRedisCluster.execute_command方法代码示例

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


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

示例1: test_refresh_table_asap

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
def test_refresh_table_asap():
    """
    If this variable is set externally, initialize() should be called.
    """
    with patch.object(NodeManager, "initialize") as mock_initialize:
        mock_initialize.return_value = None

        # Patch parse_response to avoid issues when the cluster sometimes return MOVED
        with patch.object(StrictRedisCluster, "parse_response") as mock_parse_response:

            def side_effect(self, *args, **kwargs):
                return None

            mock_parse_response.side_effect = side_effect

            r = StrictRedisCluster(host="127.0.0.1", port=7000)
            r.connection_pool.nodes.slots[12182] = [
                {"host": "127.0.0.1", "port": 7002, "name": "127.0.0.1:7002", "server_type": "master"}
            ]
            r.refresh_table_asap = True

            i = len(mock_initialize.mock_calls)
            r.execute_command("SET", "foo", "bar")
            assert len(mock_initialize.mock_calls) - i == 1
            assert r.refresh_table_asap is False
开发者ID:svrana,项目名称:redis-py-cluster,代码行数:27,代码来源:test_cluster_obj.py

示例2: monkey_link

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
    def monkey_link(host=None, port=None, decode_responses=False):
        """
        Helper function to return custom slots cache data from different redis nodes
        """
        if port == 7000:
            result = [[0, 5460, [b'127.0.0.1', 7000], [b'127.0.0.1', 7003]],
                      [5461, 10922, [b'127.0.0.1', 7001], [b'127.0.0.1', 7004]]]

        elif port == 7001:
            result = [[0, 5460, [b'127.0.0.1', 7001], [b'127.0.0.1', 7003]],
                      [5461, 10922, [b'127.0.0.1', 7000], [b'127.0.0.1', 7004]]]

        else:
            result = []

        r = StrictRedisCluster(host=host, port=port, decode_responses=True)
        orig_execute_command = r.execute_command

        def execute_command(*args, **kwargs):
            if args == ("cluster", "slots"):
                return result
            return orig_execute_command(*args, **kwargs)

        r.execute_command = execute_command
        return r
开发者ID:huangfupeng,项目名称:redis-py-cluster,代码行数:27,代码来源:test_node_manager.py

示例3: test_ask_redirection

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
def test_ask_redirection():
    """
    Test that the server handles ASK response.

    At first call it should return a ASK ResponseError that will point
    the client to the next server it should talk to.

    Important thing to verify is that it tries to talk to the second node.
    """
    r = StrictRedisCluster(host="127.0.0.1", port=7000)

    m = Mock(autospec=True)

    def ask_redirect_effect(connection, command_name, **options):
        def ok_response(connection, command_name, **options):
            assert connection.host == "127.0.0.1"
            assert connection.port == 7001

            return "MOCK_OK"

        m.side_effect = ok_response
        raise AskError("1337 127.0.0.1:7001")

    m.side_effect = ask_redirect_effect

    r.parse_response = m
    assert r.execute_command("SET", "foo", "bar") == "MOCK_OK"
开发者ID:svrana,项目名称:redis-py-cluster,代码行数:29,代码来源:test_cluster_obj.py

示例4: test_ask_redirection

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
def test_ask_redirection():
    """
    Test that the server handles ASK response.

    At first call it should return a ASK ResponseError that will point
    the client to the next server it should talk to.

    Important thing to verify is that it tries to talk to the second node.
    """
    r = StrictRedisCluster(host="127.0.0.1", port=7000)
    r.connection_pool.nodes.nodes["127.0.0.1:7001"] = {
        "host": u"127.0.0.1",
        "server_type": "master",
        "port": 7001,
        "name": "127.0.0.1:7001",
    }
    with patch.object(StrictRedisCluster, "parse_response") as parse_response:

        host_ip = find_node_ip_based_on_port(r, "7001")

        def ask_redirect_effect(connection, *args, **options):
            def ok_response(connection, *args, **options):
                assert connection.host == host_ip
                assert connection.port == 7001

                return "MOCK_OK"

            parse_response.side_effect = ok_response
            raise AskError("1337 {0}:7001".format(host_ip))

        parse_response.side_effect = ask_redirect_effect

        assert r.execute_command("SET", "foo", "bar") == "MOCK_OK"
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:35,代码来源:test_cluster_obj.py

示例5: test_ask_redirection

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
def test_ask_redirection():
    """
    Test that the server handles ASK response.

    At first call it should return a ASK ResponseError that will point
    the client to the next server it should talk to.

    Important thing to verify is that it tries to talk to the second node.
    """
    r = StrictRedisCluster(host="127.0.0.1", port=7000)
    r.connection_pool.nodes.nodes['127.0.0.1:7001'] = {
        'host': u'127.0.0.1',
        'server_type': 'master',
        'port': 7001,
        'name': '127.0.0.1:7001'
    }

    m = Mock(autospec=True)

    host_ip = find_node_ip_based_on_port(r, '7001')

    def ask_redirect_effect(connection, *args, **options):
        def ok_response(connection, *args, **options):
            assert connection.host == host_ip
            assert connection.port == 7001

            return "MOCK_OK"
        m.side_effect = ok_response
        raise AskError("1337 {0}:7001".format(host_ip))

    m.side_effect = ask_redirect_effect

    r.parse_response = m
    assert r.execute_command("SET", "foo", "bar") == "MOCK_OK"
开发者ID:JASON0916,项目名称:redis-py-cluster,代码行数:36,代码来源:test_cluster_obj.py

示例6: test_refresh_table_asap

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import execute_command [as 别名]
def test_refresh_table_asap():
    """
    If this variable is set externally, initialize() should be called.
    """
    with patch.object(NodeManager, 'initialize') as mock_initialize:
        mock_initialize.return_value = None

        r = StrictRedisCluster(host="127.0.0.1", port=7000)
        r.connection_pool.nodes.slots[12182] = {
            "host": "127.0.0.1",
            "port": 7002,
            "name": "127.0.0.1:7002",
            "server_type": "master",
        }
        r.refresh_table_asap = True

        i = len(mock_initialize.mock_calls)
        r.execute_command("SET", "foo", "bar")
        assert len(mock_initialize.mock_calls) - i == 1
        assert r.refresh_table_asap is False
开发者ID:huangfupeng,项目名称:redis-py-cluster,代码行数:22,代码来源:test_cluster_obj.py


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