Fixed Redis connectivity problems number one and two
Before that fix, it was not possible to use library when Redis restarts sometimes.
Please merge this PR or previous one (#337) and also backport one of them to all older versions, as the bug renders library impossible to use with Redis in production.
@Krukov actually this PR is not so good, you shall use redis_connect_func=...:
def redis_connect_func(connection):
connection.on_connect()
fill_in_hashes...
keeping in mind that client may have multiple connections and they can be routed to different instances of Redis.
Also, I would recommend to pull backend implementation/interface code from limits, all of these is solved there already.
https://pypi.org/project/limits/
Thanks,
I took a look and the main difference is that "limits" uses register_script instead of script_load (https://redis-py.readthedocs.io/en/stable/commands.html#redis.commands.core.CoreCommands.register_script)
You can read more here to understand why https://redis-py.readthedocs.io/en/stable/lua_scripting.html :
The Script object ensures that the Lua script is loaded into Redis’s script cache. In the event of a NOSCRIPT error, it will load the script and retry executing it.
So to solve the problem we need to use register_script too. Want to make a PR?