upstash / redis-py

HTTP based Python Redis Client for Serverless and Edge Functions
https://docs.upstash.com/redis
MIT License
29 stars 3 forks source link

Include a timeout for `session.post` in `sync_execute` #46

Open mmangus opened 5 months ago

mmangus commented 5 months ago

In sync_execute, commands are executed by making requests to the Upstash REST API like this...

response = session.post(url, headers=headers, json=command).json()

...where session is a requests.Session instance.

As indicated by the requests documentation, this call should include a timeout to avoid blocking for long periods in the event of networking trouble:

Nearly all production code should use this parameter [timeout] in nearly all requests. Failure to do so can cause your program to hang indefinitely

For the Redis workloads I typically have, no response from Redis is better than a slow response from Redis. The client should at least allow users to configure a timeout for these requests, and in my opinion should also have a default timeout enabled without user intervention.