ExHammer / hammer

An Elixir rate-limiter with pluggable backends
https://hexdocs.pm/hammer/
MIT License
749 stars 42 forks source link

Allow all key types #37

Closed tanguilp closed 1 year ago

tanguilp commented 6 years ago

Hi,

One improvement idea: allowing any key type (any erlang term) for keys, and letting the backend to deal with it if unsupported. For instance, if I want to throttle an API on IP address, machine id and and user id, I might want to store it directly as a key ([{122, 12, 243,109}, "device_382719", "edward03"]) or a hash of it (:erlang.phash2([{122, 12, 243,109}, "device_382719", "edward03"]) which returns an integer).

ETS and Mnesia could store both forms as-is (not sure about the performances when storing the non-hashed key though, guess it depends on the length). As of today, the mandatory conversion to a binary might unnecessarily degrade performance.

JuneKelly commented 5 years ago

That's a cool suggestion, I'll see if it's feasible :+1:

epinault commented 1 year ago

@tanguilp do you still need this feature?

tanguilp commented 1 year ago

Not really that was just a suggestion and I’m no longer sure it’sa good one 🙂