cashews icon indicating copy to clipboard operation
cashews copied to clipboard

Fixed Redis connectivity problems number one and two

Open excitoon opened this issue 9 months ago • 4 comments

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.

excitoon avatar Feb 28 '25 05:02 excitoon

@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.

excitoon avatar Mar 09 '25 11:03 excitoon

Also, I would recommend to pull backend implementation/interface code from limits, all of these is solved there already.

excitoon avatar Mar 17 '25 11:03 excitoon

https://pypi.org/project/limits/

excitoon avatar Mar 17 '25 11:03 excitoon

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?

Krukov avatar Mar 17 '25 20:03 Krukov