5 ms·
Show HN: Redis-cell, an API rate limiter as a Redis module, written in Rust
- brandur 10y agoAuthor here: this was a pretty fun side project to experiment with Redis' (relatively) new module system [1], and to help me learn Rust. It uses Rust's FFI module [2] to call into a C binary, and thanks to Rust's minimal runtime and lack of a GC, this turns out to work out very well. Its benchmarks are quite good [3]. Redis provides a fairly novel API for plugging into it in that instead of using a shared object (.so), it's only exposed as a C header file. To compensate for this in a non-C language, I have a build step that compiles a library for Rust to link against [4]. It was a pleasant surprise to find that this functionality is built right into Rust's compiler. [1] https://github.com/antirez/redis/blob/unstable/src/modules/INTRO.md https://github.com/antirez/redis/blob/unstable/src/modules/I... [2] https://doc.rust-lang.org/book/ffi.html https://doc.rust-lang.org/book/ffi.html [3] https://gist.github.com/brandur/90698498bd543598d00df46e32be3268 https://gist.github.com/brandur/90698498bd543598d00df46e32be... [4] https://github.com/brandur/redis-cell/blob/master/build.rs https://github.com/brandur/redis-cell/blob/master/build.rs