本文整理汇总了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
示例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
示例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"
示例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"
示例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"
示例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