PHP code example of mu / bloomfilter
1. Go to this page and download the library: Download mu/bloomfilter 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 / bloomfilter example snippets
use Mu\Bloomfilter\BloomFilter;
# redis服务器
$redis_conf = [
'host' => '127.0.0.1',
'port' => 6379,
'auth' => 'beauty',
'timeout' => 1,
'database' =>0
];
$bloomfilter = new BloomFilter($redis_conf);
# 设置评论的空间
$bloomfilter->set_bucket('black_ips');
# 添加一个ip
$ip = '127.0.0.1';
$add_rs = $bloomfilter->add($ip);
# 批量添加
$ips = ['192.168.0.1','192.168.0.2'];
$adds_rs = $bloomfilter->multi_add($ips);
# 检查ip
$rs = $bloomfilter->exists($ip);
# 批量检查ip
$multi_rs = $bloomfilter->multi_exists($ips);