redis_rate
redis_rate copied to clipboard
feat: make key prefix configurable
This PR will allow the Limiter to be optionally configured with a key prefix. This makes the limiter more flexible as not all applications need to be prefixed with rate:.
Using the Options pattern ensures we do not break backwards compatibility and will still use the default value.
Users of this package can chose to:
- Not use
WithKeyPrefixwhen initializing the limiter to use the default value ofrate: - Set
WithKeyPrefix("")to remove all prefixes from the used keys. - Set whatever prefix they want.
I extended the TestAllow to use different key prefixes. I don't think it's necessary to extend the other tests as this already shows things work as expected.
For extra context, we are looking at using this package for https://gitlab.com/gitlab-org/container-registry, however this is a current limitation we have given our guidelines.
@vmihailenco would you consider this change?
cc @joaodrp