Skip to content

Commit

Permalink
Merge pull request #209 from NimrodParasol/eval-redis-dict-results-lu…
Browse files Browse the repository at this point in the history
…a-objects

Redis operation that returns dict now converted to Lua table when called inside eval operation
  • Loading branch information
bmerry committed Aug 21, 2018
2 parents c3c45af + b461534 commit 721669e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,12 @@ def eval(self, script, numkeys, *keys_and_args):

def _convert_redis_result(self, lua_runtime, result):
if isinstance(result, dict):
return [
converted = [
i
for item in result.items()
for i in item
]
return lua_runtime.table_from(converted)
elif isinstance(result, set):
converted = sorted(
self._convert_redis_result(lua_runtime, item)
Expand Down
16 changes: 16 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,22 @@ def test_eval_hgetall(self):
[[b'k1', b'bar'], [b'k2', b'baz']]
)

def test_eval_hgetall_iterate(self):
self.redis.hset('foo', 'k1', 'bar')
self.redis.hset('foo', 'k2', 'baz')
lua = """
local result = redis.call("hgetall", "foo")
for i, v in ipairs(result) do
end
return result
"""
val = self.redis.eval(lua, 1, 'foo')
sorted_val = sorted([val[:2], val[2:]])
self.assertEqual(
sorted_val,
[[b'k1', b'bar'], [b'k2', b'baz']]
)

def test_eval_list_with_nil(self):
self.redis.lpush('foo', 'bar')
self.redis.lpush('foo', None)
Expand Down

0 comments on commit 721669e

Please sign in to comment.