def test_execute_commands(cluster): TestScript = Script( cluster.get_local_client(0), "return {KEYS, ARGV}", ) # XXX: redis<2.10.6 didn't require that a ``Script`` be instantiated with a # valid client as part of the constructor, which resulted in the SHA not # actually being set until the script was executed. To ensure the legacy # behavior still works, we manually unset the cached SHA before executing. actual_script_hash = TestScript.sha TestScript.sha = None results = cluster.execute_commands({ "foo": [ ("SET", "foo", "1"), (TestScript, ("key", ), ("value", )), ("GET", "foo"), ], "bar": [ ("INCRBY", "bar", "2"), (TestScript, ("key", ), ("value", )), ("GET", "bar"), ], }) assert TestScript.sha == actual_script_hash assert results["foo"][0].value assert results["foo"][1].value == [["key"], ["value"]] assert results["foo"][2].value == "1" assert results["bar"][0].value == 2 assert results["bar"][1].value == [["key"], ["value"]] assert results["bar"][2].value == "2"
def test_execute_commands(cluster): TestScript = Script( cluster.get_local_client(0), 'return {KEYS, ARGV}', ) # XXX: redis<2.10.6 didn't require that a ``Script`` be instantiated with a # valid client as part of the constructor, which resulted in the SHA not # actually being set until the script was executed. To ensure the legacy # behavior still works, we manually unset the cached SHA before executing. actual_script_hash = TestScript.sha TestScript.sha = None results = cluster.execute_commands({ 'foo': [ ('SET', 'foo', '1'), (TestScript, ('key', ), ('value', )), ('GET', 'foo'), ], 'bar': [ ('INCRBY', 'bar', '2'), (TestScript, ('key', ), ('value', )), ('GET', 'bar'), ], }) assert TestScript.sha == actual_script_hash assert results['foo'][0].value assert results['foo'][1].value == [['key'], ['value']] assert results['foo'][2].value == '1' assert results['bar'][0].value == 2 assert results['bar'][1].value == [['key'], ['value']] assert results['bar'][2].value == '2'