百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

redis-shield

> 数据库
开源

Redis 和 Valkey 模块,它将 token-bucket 算法实现为原生命令,用于高性能的速率限制

99 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Redis 和 Valkey 模块,它将 token-bucket 算法实现为原生命令,用于高性能的速率限制

Redis Shield

Redis Shield is a loadable module for Redis and Valkey that implements the token bucket algorithm to do rate limiting as a native command. The same compiled artifact loads into either server.

Algorithm

The token bucket algorithm is based on an analogy of a fixed capacity bucket into which tokens are added at a fixed rate. When a request is to be checked for conformance to the defined limits, the bucket is inspected to see if it contains sufficient tokens at that time. If so, the appropriate number of tokens, e.g. equivalent to the number of HTTP requests, are removed, and the request is passed.

The request does not conform if there are insufficient tokens in the bucket.

Install

Clone and build the project from source.

$ git clone https://github.com/ayarotsky/redis-shield.git
$ cd redis-shield
$ cargo build --release
$ # extension will be **.dylib** instead of **.so** for Mac releases
$ cp target/release/libredis_shield.so /path/to/modules/

Run redis-server or valkey-server pointing to the newly built module:

redis-server  --loadmodule /path/to/modules/libredis_shield.so
valkey-server --loadmodule /path/to/modules/libredis_shield.so

Or add the following to a redis.conf or valkey.conf file:

loadmodule /path/to/modules/libredis_shield.so

Usage

SHIELD.absorb    []

Where key is a unique bucket identifier. Examples:

  • User ID
  • Request's IP address

For example:

SHIELD.absorb ip-127.0.0.1 30 60 11
                ▲           ▲  ▲ ▲
                |           |  | └─── take 11 token (default is 1 if omitted)
                |           |  └───── 60 seconds
                |           └──────── 30 tokens
                └──────────────────── key "ip-127.0.0.1"

The command responds with the number of tokens left in the bucket. -1 is returned when the bucket is overflown.

127.0.0.1:6379> SHIELD.absorb user123 30 60 13
(integer) 17
127.0.0.1:6379> SHIELD.absorb user123 30 60 13
(integer) 4
127.0.0.1:6379> SHIELD.absorb user123 30 60 13
(integer) -1

Contributing

Interested in contributing? See CONTRIBUTING.md for:

  • Development setup
  • Running tests and benchmarks
  • Code style guidelines
  • Pull request process

License

This is free software under the terms of MIT the license (see the file LICENSE for details).

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustrate-limitingredisredis-modulerust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库