Skip to content

Leaky bucket throttling as a redis module, implemented in rust (mostly for learning)

License

Notifications You must be signed in to change notification settings

dgrijalva/rust_bucket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust_bucket

Leaky bucket throttling as a redis module, implemented in rust (mostly for learning)

I pretty much just wrote this to mess around with FFI and the redis module API. It turns out, someone already published a pretty nice rust crate for building redis modules (thanks!).

Using this

cargo build --release should produce a shared library that can be directly loaded into redis using the MODULE LOAD command.

bucket.create foo 1000 1 will create a bucket at the key foo that holds 1000 tokens and adds 1 token every 1ms.

bucket.take foo will attempt to take one token from the bucket, returning either 0 or 1.

bucket.take foo 10 will attempt to take 10 tokens from the bucket, returning either 0 or 10.

bucket.peek foo will return the number of tokens currently in the bucket.

TODO

  • Add support for adding more than one token per ms. How should it be specified? Extra argument? Negative add_rate?

About

Leaky bucket throttling as a redis module, implemented in rust (mostly for learning)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages