add more discussion to INCR docu case studies #2722
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The discussion about implementing a rate limiter pattern contained in the docu about INCR command may lead one to think that the rate limiter pattern is made somewhat more complicated due to INCR not having NX features similar to SET. This is because a very simple but flawed example is demonstrated, and the working solutions all either use timestamps within the buckets (which adds complexity, and raises questions about clock synchronization across servers), or use lua scripting, or use redis lists. Meanwhile an NX feature on INCR would seem to solve the problem pointed out in the flawed example.
This idea re-appears in github issues where users request additional features to be added to INCR, and point to rate limiter as a motivation:
redis/redis#4423
redis/redis#7631
In all the comments, more experienced users explain how you can already basically do this using a MULTI pipeline, and you can use NX in that pipeline as well if you want, which would accomplish what these feature requests seem to be asking for. However, this idea doesn't actually appear in the case studies in the documentation.
Expanding the case studies to include this idea, and working through explicitly how it avoids race conditions and pitfalls described in the other approaches, may be helpful to users. (It was helpful to me.)