jamesls/fakeredis

fakeredis should support `execute_command` method

lfyzjck opened this issue · 6 comments

In some cases, people may use redis.Redis.execute_command directly

here is an example implement:

def execute_command(self, *args, **options):
    "Execute a command and return a parsed response"
    command_name = args[0]
    command = getattr(self, command_name, None)
    if command:
        return command(*args[-1:], **options)
    else:
        raise redis.ResponseError("command {0} is not supported.".format(command_name))

I have not test the code yet...

+1

Any update on this? Any reason it's not one of the commands listed as "unimplemented" in the documentation?

Issue with the code snippet above is that redispy has limited functionality with certain calls, eg zadd: as it currently exists, can't use xx or nx flags directly in zadd calls.

So, my solution was to monkeypatch zadd to call execute_command() with something like this suggestion. This works in redispy, but wouldn't work in the above snippet because it would just call the already-lacking zadd.

execute_command is fully supported in 1.0rc1, so I'm going to close this.

Unfortunately your specific use case (zadd with xx/nx) still isn't implemented, but it shouldn't be too hard to implement. Pull requests welcome.