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


Python StrictRedisCluster.pipeline方法代码示例

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


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

示例1: test_pipeline_ask_redirection

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

    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)
    with patch.object(StrictRedisCluster, "parse_response") as parse_response:

        def response(connection, *args, **options):
            def response(connection, *args, **options):
                def response(connection, *args, **options):
                    assert connection.host == "127.0.0.1"
                    assert connection.port == 7001
                    return "MOCK_OK"

                parse_response.side_effect = response
                raise AskError("12182 127.0.0.1:7001")

            parse_response.side_effect = response
            raise AskError("12182 127.0.0.1:7001")

        parse_response.side_effect = response

        p = r.pipeline()
        p.set("foo", "bar")
        assert p.execute() == ["MOCK_OK"]
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:32,代码来源:test_cluster_obj.py

示例2: test_moved_redirection_pipeline

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import pipeline [as 别名]
def test_moved_redirection_pipeline():
    """
    Test that the server handles MOVED response when used in pipeline.

    At first call it should return a MOVED 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)
    p = r.pipeline()

    m = Mock(autospec=True)

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

            return "MOCK_OK"

        m.side_effect = ok_response
        raise MovedError("12182 127.0.0.1:7002")

    m.side_effect = moved_redirect_effect

    p.parse_response = m
    p.set("foo", "bar")
    assert p.execute() == ["MOCK_OK"]
开发者ID:svrana,项目名称:redis-py-cluster,代码行数:31,代码来源:test_cluster_obj.py

示例3: test_moved_redirection_pipeline

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import pipeline [as 别名]
def test_moved_redirection_pipeline():
    """
    Test that the server handles MOVED response when used in pipeline.

    At first call it should return a MOVED 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.
    """
    with patch.object(StrictRedisCluster, 'parse_response') as parse_response:
        def moved_redirect_effect(connection, *args, **options):
            def ok_response(connection, *args, **options):
                assert connection.host == "127.0.0.1"
                assert connection.port == 7002

                return "MOCK_OK"
            parse_response.side_effect = ok_response
            raise MovedError("12182 127.0.0.1:7002")

        parse_response.side_effect = moved_redirect_effect

        r = StrictRedisCluster(host="127.0.0.1", port=7000)
        p = r.pipeline()
        p.set("foo", "bar")
        assert p.execute() == ["MOCK_OK"]
开发者ID:Grokzen,项目名称:redis-py-cluster,代码行数:27,代码来源:test_cluster_obj.py

示例4: test_cluster_of_one_instance

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import pipeline [as 别名]
def test_cluster_of_one_instance():
    """
    Test a cluster that starts with only one redis server and ends up with
    one server.

    There is another redis server joining the cluster, hold slot 0, and
    eventually quit the cluster. The StrictRedisCluster instance may get confused
    when slots mapping and nodes change during the test.
    """
    with patch.object(StrictRedisCluster, "parse_response") as parse_response_mock:
        with patch.object(NodeManager, "initialize", autospec=True) as init_mock:

            def side_effect(self, *args, **kwargs):
                def ok_call(self, *args, **kwargs):
                    assert self.port == 7007
                    return "OK"

                parse_response_mock.side_effect = ok_call

                raise ClusterDownError("CLUSTERDOWN The cluster is down. Use CLUSTER INFO for more information")

            def side_effect_rebuild_slots_cache(self):
                # make new node cache that points to 7007 instead of 7006
                self.nodes = [{"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"}
                    ]

                # Second call should map all to 7007
                def map_7007(self):
                    self.nodes = [
                        {"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"}
                        ]

                # First call should map all to 7006
                init_mock.side_effect = map_7007

            parse_response_mock.side_effect = side_effect
            init_mock.side_effect = side_effect_rebuild_slots_cache

            rc = StrictRedisCluster(host="127.0.0.1", port=7006)
            rc.set("foo", "bar")

            #####
            # Test that CLUSTERDOWN is handled the same way when used via pipeline

            parse_response_mock.side_effect = side_effect
            init_mock.side_effect = side_effect_rebuild_slots_cache

            rc = StrictRedisCluster(host="127.0.0.1", port=7006)
            p = rc.pipeline()
            p.set("bar", "foo")
            p.execute()
开发者ID:svrana,项目名称:redis-py-cluster,代码行数:64,代码来源:test_cluster_obj.py

示例5: StrictRedisCluster

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

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

# This line initialize a redis cluster client obj.
# Will raise RedisClusterException on connection failed.
# The 'decode_responses=True' is needed for Python3
rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)

# For Redis command per call, please refer: 
#   https://redis-py.readthedocs.org/en/latest/
maxacc = rc.get('UniqueID:Account')
print('Maximum Account ID is ' + maxacc)

# Demo of pipeline (batch) usage
rcp = rc.pipeline(transaction=False)
rcp.command_stack = []

curacci = 133589
maxacci = int(maxacc)
for acc in range(curacci, maxacci+1):
  rcp.command_stack.append((['HGETALL', 'Account:-' + str(acc)], {}))

print('Pipelining ' + str(len(rcp.command_stack)) + ' Redis queries.')
# A list of dict. One dict is a HGETALL result of an account.
result = rcp.execute()

print('Query finished.')
print(result)

开发者ID:matthklo,项目名称:snippetcache,代码行数:30,代码来源:redis_cluster.py

示例6: StrictRedisCluster

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

from rediscluster import StrictRedisCluster

# ###################################################################################################################
REDIS_HOST = "X.X.X.X"
REDIS_PORT = 6379
redis_connection = StrictRedisCluster(REDIS_HOST, REDIS_PORT)
STR_TO_MATCH = ""
# cluster mode rules out the transactional pipeline
pipeline = redis_connection.pipeline(transaction=False)

# create an generator to efficiently iterate the keys
generator = redis_connection.scan_iter(match=STR_TO_MATCH+"*")
for event in generator:
    event_key = event[4:]
    if 1 == 1:
        pipeline.delete(event)

pipeline.execute()
开发者ID:Ziolass,项目名称:CodeSnippets,代码行数:22,代码来源:simple_redis.py

示例7: StrictRedisCluster

# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import pipeline [as 别名]
    查询使用pipeline减少交互,提高效率。
"""

from rediscluster import StrictRedisCluster


# 导出
redis_cluster_export = [{'host': '172.28.247.114', 'port': '28000'},
                        {'host': '172.28.247.114', 'port': '28001'},
                        {'host': '172.28.247.114', 'port': '28002'},
                        {'host': '172.28.247.114', 'port': '28003'},
                        {'host': '172.28.247.114', 'port': '28004'},
                        {'host': '172.28.247.114', 'port': '28005'},
                        ]
redis_cluster_export_conn = StrictRedisCluster(startup_nodes=redis_cluster_export, decode_responses=True)
pipe = redis_cluster_export_conn.pipeline()
redis_size = 100000

# 导入
redis_cluster_import = [{'host': '172.28.250.142', 'port': '28000'},
                        {'host': '172.28.250.142', 'port': '28001'},
                        {'host': '172.28.250.142', 'port': '28002'},
                        {'host': '172.28.250.142', 'port': '28003'},
                        {'host': '172.28.250.142', 'port': '28004'},
                        {'host': '172.28.250.142', 'port': '28005'},
                        ]
redis_cluster_import_conn = StrictRedisCluster(startup_nodes=redis_cluster_import, decode_responses=True)


def redis_set():
    key_len = 0
开发者ID:jameyang,项目名称:python,代码行数:33,代码来源:redis_export_v2.py


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