PHP code example of mu / redis-limiter

1. Go to this page and download the library: Download mu/redis-limiter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mu / redis-limiter example snippets


$redisConf = [
	'host' => '127.0.0.1',
	'port' => 16379,
	'auth' => ''
];
Limit::setRedisConf($redisConf);

Limit::getInstance()->addItem('default')->setMax('1r/s');

if (Limit::isAllow('default')){
    echo '成功',PHP_EOL;
}else{
    echo '失败',PHP_EOL;
}
bash
 Mu\Juyuan\Limit;
$redisConf = [
	'host' => '127.0.0.1',
	'port' => 16379,
	'auth' => ''
];
Limit::setRedisConf($redisConf);
Limit::getInstance()->addItem('default')->setMax('1r/s');
for ($i=0;$i<100;$i++){
	usleep(500000);
	echo '['.date('Y-m-d H:i:s').']';
	if (Limit::isAllow('default')){
		echo '成功',PHP_EOL;
	}else{
		echo '失败',PHP_EOL;
	}
}