應(yīng)用接口服務(wù)限流工具,簡(jiǎn)單實(shí)現(xiàn)令牌桶

v1.0.1
版本
2022-04-06
版本更新時(shí)間
737
安裝
16
star
簡(jiǎn)介
限流類(lèi)
- 全局中間件,整個(gè)應(yīng)用接口限流,
- 路由中間件,某些功能接口請(qǐng)求速率限制
緩存依據(jù)的是Support\Cache的 instance()
, 其他類(lèi)只要是實(shí)現(xiàn) get($key, $default = null)
, set($key, $value, $ttl = null)
, delete($key)
funtion就行.
項(xiàng)目地址:https://github.com/nsp-team/webman-throttler
安裝
composer require nsp-team/webman-throttler
使用
默認(rèn) 開(kāi)啟全局中間件限流
return [
'' => [
\NspTeam\WebmanThrottler\Middleware\ThrottlerMiddleware::class,
]
];
你也可以啟用路由中間件,控制接口請(qǐng)求速率限制
例如:
Route::group('/sys/user', static function () {
Route::post('/test', [User::class, 'test']);
})->middleware([
\NspTeam\WebmanThrottler\Middleware\ThrottlerMiddleware::class
]);