Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error calling redis command with arguments in lua eval #220

Closed
dkong opened this issue Oct 17, 2018 · 4 comments
Closed

Error calling redis command with arguments in lua eval #220

dkong opened this issue Oct 17, 2018 · 4 comments

Comments

@dkong
Copy link

dkong commented Oct 17, 2018

Test case demonstrating the issue:

    def test_eval_zrange(self):
        self.redis.zadd('foo', 1, 'bar')
        val = self.redis.eval(
            '''
            return redis.call("ZRANGE", KEYS[1], ARGV[1], ARGV[2]);
            ''', 1, 'foo', 0, -1
        )
        self.assertEqual(val, ['bar'])

And the error (using HEAD):

$ nosetests test_fakeredis.py:TestFakeStrictRedis.test_eval_zrange
E
======================================================================
ERROR: test_eval_zrange (test_fakeredis.TestFakeStrictRedis)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/dara/dev/fakeredis/test_fakeredis.py", line 3673, in test_eval_zrange
    ''', 1, 'foo', 0, -1
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 502, in func_wrapper
    return func(*args, **kwargs)
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 510, in func_wrapper
    ret = func(self, *args, **kwargs)
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 1061, in eval
    result = lua_runtime.execute(script)
  File "lupa/_lupa.pyx", line 262, in lupa._lupa.LuaRuntime.execute
  File "lupa/_lupa.pyx", line 1279, in lupa._lupa.run_lua
  File "lupa/_lupa.pyx", line 1288, in lupa._lupa.call_lua
  File "lupa/_lupa.pyx", line 1313, in lupa._lupa.execute_lua_call
  File "lupa/_lupa.pyx", line 235, in lupa._lupa.LuaRuntime.reraise_on_exception
  File "lupa/_lupa.pyx", line 1451, in lupa._lupa.py_call_with_gil
  File "lupa/_lupa.pyx", line 1438, in lupa._lupa.call_python
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 1177, in _lua_redis_call
    result = func(self, *args)
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 510, in func_wrapper
    ret = func(self, *args, **kwargs)
  File "/Users/dara/dev/fakeredis/fakeredis.py", line 1920, in zrange
    end += 1
TypeError: coercing to Unicode: need string or buffer, int found

----------------------------------------------------------------------
Ran 1 test in 0.006s

FAILED (errors=1)

Python version:

Python 2.7.14 (default, Feb  6 2018, 20:03:13)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin

Seems related to the conversion here:

keys_and_args = [to_bytes(v) for v in keys_and_args]

@bmerry
Copy link
Collaborator

bmerry commented Oct 18, 2018

There are probably going to be a whole bunch of these, which are because the Lua support just connects directly to the Python API, rather than to an emulation of the redis wire protocol. It would probably need #65 to fix that.

If you wanted to fix just this particular issue, I think the fix would be to have ZRANGE accept strings where it takes ints. Pull requests welcome.

You might also want to check out birdisle, which won't have these sort of problems, but isn't quite production-ready.

@dkong
Copy link
Author

dkong commented Oct 25, 2018

Thanks, that looks promising!

I ran into several issues and was able to hack the library to get it mostly working in my narrow use case. But it's nowhere clean enough to submit a PR yet.

@bmerry
Copy link
Collaborator

bmerry commented Oct 26, 2018

Incidentally I've just made the initial release of birdisle, so you should be able to pip install it and try it out.

@bmerry
Copy link
Collaborator

bmerry commented Jan 14, 2019

This should be fixed in 1.0rc1, although I haven't specifically tested it. Feel free to contribute a PR to add the test, and re-open if it still doesn't work.

@bmerry bmerry closed this as completed Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants