-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
54 lines (45 loc) · 1.03 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
include './vendor/autoload.php';
/**
* 缓存key不存在,过滤器
*
* 该布隆过滤器总位数为2^32位, 判断条数为2^30条. hash函数最优为3个.(能够容忍最多的hash函数个数)
* 使用的三个hash函数为
* BKDR, SDBM, JSHash 等*/
class FilterNotKey extends \Bloom\FilterRedis
{
/**
* 不存在key,过滤器
* @var string
*/
protected $bucket = 'not:key';
/**
* @var array $hashFunction 哈希算法
*/
protected $hashFunction = ['BKDRHash', 'SDBMHash', 'JSHash'];
}
/**
* Redis
*/
$config = [
'host' => '127.0.0.1'
, 'port' => 6379,
];
$filterObj = new FilterNotKey($config, 0);
/**
* 开始测试*/
$exit = $filterObj->exists('10');
var_dump($exit);
if (!$exit) {
$add = $filterObj->add('10');
var_dump(json_encode($add));
}
$exit = $filterObj->exists('130');
var_dump($exit);
if (!$exit) {
$add = $filterObj->add('130');
var_dump(json_encode($add));
}
$exit = $filterObj->exists('33');
var_dump($exit);
echo "----[ok]----" . "\n";