0

I'm having a single redis server serve multiple clients. Sometimes server needs to run a lua script that takes around a minute to complete. However during that time other clients get response error:

redis.exceptions.ResponseError: BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE

Is there in built way to tell client to just keep waiting or retrying this response?
Redis(socket_timeout=9999) doesn't seem to have an effect on this.

1
  • I would go opposite way - try with short timeout, and retry at your side... It allows you to have better control on timeouts. Also note that system can have settings that interfere with yours - at least that was the case under Linux some time ago... Commented Aug 20, 2018 at 11:05

1 Answer 1

2

I couldn't find a proper way to do so I went with a bit of a hack:

from redis import Redis

class MyRedis(Redis):
    lua_retry_time = 120

    # override execute to retry busy errors 
    def execute_command(self, *args, **options):
        wait_time = 0
        if not self.lua_retry_time:
            return super().execute_command(*args, **options)
        while wait_time < self.lua_retry_time:
            try:
                return super().execute_command(*args, **options)
            except ResponseError as e:
                if 'busy redis is busy' not in ''.join(e.args).lower():
                    raise e
                if wait_time == 0:  # only print once
                    print('Redis is busy, waiting up to 120 seconds...')
                time.sleep(2)
                wait_time += 2
        return super().execute_command(*args, **options)

Every command in redis-py package goes through execute_command method this this should cover everything. This will keep retrying for 120 seconds every 2 seconds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.