本文整理汇总了Python中rediscluster.StrictRedisCluster.parse_response方法的典型用法代码示例。如果您正苦于以下问题:Python StrictRedisCluster.parse_response方法的具体用法?Python StrictRedisCluster.parse_response怎么用?Python StrictRedisCluster.parse_response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rediscluster.StrictRedisCluster
的用法示例。
在下文中一共展示了StrictRedisCluster.parse_response方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ask_redirection
# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import parse_response [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"
示例2: test_moved_redirection
# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import parse_response [as 别名]
def test_moved_redirection():
"""
Test that the client handles MOVED response.
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)
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 == 7002
return "MOCK_OK"
m.side_effect = ok_response
raise MovedError("12182 127.0.0.1:7002")
m.side_effect = ask_redirect_effect
r.parse_response = m
assert r.set("foo", "bar") == "MOCK_OK"
示例3: test_ask_redirection
# 需要导入模块: from rediscluster import StrictRedisCluster [as 别名]
# 或者: from rediscluster.StrictRedisCluster import parse_response [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
resp = ResponseError()
resp.message = "ASK 1337 127.0.0.1:7001"
raise resp
m.side_effect = ask_redirect_effect
r.parse_response = m
assert r.execute_command("SET", "foo", "bar") == "MOCK_OK"