codeages/token-bucket

v0.1.0 2016-12-13 06:54 UTC

This package is auto-updated.

Last update: 2020-11-06 08:01:48 UTC


README

  • use composer
    composer require codeages/token-bucket
    

notice

  • add redis mux key support for concurrency
  • remove the db support

Usage

  • example
    $tokens = 30; //the bucket capacity
    $rates = 10; //recover tokens per second
    $consume = 10; //consume tokens
    $key = "test"; //bucket name
    
    $redis = new \Redis();
    $redis->connect('127.0.0.1', 6379, 1);
    $driver = new RedisDriver("test", $redis);
    $tokenBucket = new TokenBucket($tokens, $rates, $name);
    $tokenBucket->setDriver($driver)->watch();
    
    $tokenBucket->consume($consume);