From ddf0b5d8d6587de9abd369e7715a3b57e91d8045 Mon Sep 17 00:00:00 2001 From: kehati Date: Thu, 2 Jul 2015 15:09:10 +0300 Subject: [PATCH 1/2] Convrting LUA keys and args to strings to comply with redis --- mockredis/script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mockredis/script.py b/mockredis/script.py index c0a3d48..afc41cf 100644 --- a/mockredis/script.py +++ b/mockredis/script.py @@ -24,7 +24,7 @@ def __call__(self, keys=[], args=[], client=None): if not client.script_exists(self.sha)[0]: self.sha = client.script_load(self.script) - return self._execute_lua(keys, args, client) + return self._execute_lua([str(key) for key in keys], [str(arg) for arg in args], client) def _execute_lua(self, keys, args, client): """ From 390bbb4c4be935006bbd6b7221ffd771771fe408 Mon Sep 17 00:00:00 2001 From: Amotz Getzov Date: Tue, 28 Jun 2016 16:18:53 +0300 Subject: [PATCH 2/2] Unit test for Lua arguments conversion to string. --- mockredis/tests/test_script.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mockredis/tests/test_script.py b/mockredis/tests/test_script.py index bb000b6..85e164d 100644 --- a/mockredis/tests/test_script.py +++ b/mockredis/tests/test_script.py @@ -240,6 +240,12 @@ def test_table_type(self): itemType = script(keys=[LIST1], args=[0, -1]) eq_('table', itemType) + def test_string_arguments(self): + script_content = "return type(KEYS[1]) .. type(KEYS[2]) .. type(ARGV[1]) .. type(ARGV[2])" + script = self.redis.register_script(script_content) + item_types = script(keys=[64, 'abc'], args=[123, [34,43]]) + eq_('string'*4, item_types) + def test_script_hgetall(self): myhash = {"k1": "v1"} self.redis.hmset("myhash", myhash)