redis_rate icon indicating copy to clipboard operation
redis_rate copied to clipboard

feat: make key prefix configurable

Open jaimem88 opened this issue 9 months ago • 2 comments

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 WithKeyPrefix when initializing the limiter to use the default value of rate:
  • 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.

jaimem88 avatar Feb 28 '25 17:02 jaimem88

@vmihailenco would you consider this change?

jaimem88 avatar Feb 28 '25 18:02 jaimem88

cc @joaodrp

jaimem88 avatar Feb 28 '25 18:02 jaimem88