Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove call to TIME in Lua scripts #11

Merged
merged 1 commit into from
Feb 8, 2024
Merged

Conversation

klette
Copy link
Member

@klette klette commented Feb 8, 2024

TIME is not deterministic and is rejected in some Redis deployments, such as AWS ElasticCache Servless Redis.

We pass the time tuple as arguments rather than calling TIME within the Lua script.

@klette klette self-assigned this Feb 8, 2024
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Type: Enhancement

PR Summary: This pull request introduces an enhancement to the token bucket implementation by removing the direct call to the Redis TIME command within Lua scripts. Instead, it adds a new function to generate a time tuple in Python, which is then passed as arguments to the Lua script. This change addresses compatibility issues with certain Redis deployments, such as AWS ElasticCache Serverless Redis, by ensuring that the time is determined outside of the Lua script and passed in, thus avoiding the non-deterministic behavior of the TIME command.

Decision: Comment

📝 Type: 'Enhancement' - not supported yet.
  • Sourcery currently only approves 'Typo fix' PRs.
✅ Issue addressed: this change correctly addresses the issue or implements the desired feature.
No details provided.
📝 Complexity: the changes are too large or complex for Sourcery to approve.
  • Unsupported files: the diff contains files that Sourcery does not currently support during reviews.

General suggestions:

  • Ensure that the new method of passing time as arguments does not introduce any precision loss or timing issues, especially in high-load environments.
  • Consider adding a fallback mechanism or a configuration option to use the original TIME command approach for deployments where it is supported and preferred.
  • Review the overall impact of this change on the performance of the token bucket mechanism, particularly in terms of the additional overhead of calculating the time in Python and passing it to Redis.

Thanks for using Sourcery. We offer it for free for open source projects and would be very grateful if you could help us grow. If you like it, would you consider sharing Sourcery on your favourite social media? ✨

Share Sourcery

Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@klette klette force-pushed the deterministic-lua-scripts branch 2 times, most recently from 7e43605 to 56a4ba0 Compare February 8, 2024 13:36
TIME is not deterministic and is rejected in some Redis deployments,
such as AWS ElasticCache Servless Redis.

Rather than calling TIME within the lua script, we pass the information
as arguments.
@klette klette merged commit e3cf0d6 into main Feb 8, 2024
4 checks passed
@klette klette deleted the deterministic-lua-scripts branch February 8, 2024 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant