-
Notifications
You must be signed in to change notification settings - Fork 3
/
bloom-filter-copy.php
59 lines (46 loc) · 1.43 KB
/
bloom-filter-copy.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
54
55
56
57
58
59
<?php
/**
* @project phpredis-bloom
* @author Rafael Campoy <rafa.campoy@gmail.com>
* @copyright 2019 Rafael Campoy <rafa.campoy@gmail.com>
* @license MIT
* @link https://github.com/averias/phpredis-bloom
*
* Copyright and license information, is included in
* the LICENSE file that is distributed with this source code.
*/
namespace Example;
require(dirname(__DIR__) . '/vendor/autoload.php');
use Averias\RedisBloom\Enum\OptionalParams;
use Averias\RedisBloom\Factory\RedisBloomFactory;
const SCAN_KEY = 'scan-key';
const TARGET_SCAN_KEY = 'target-scan-key';
$factory = new RedisBloomFactory();
$client = $factory->createClient();
$capacity = 10000;
$insertData = [];
for ($i = 0; $i < $capacity; $i++) {
$insertData[] = "abc{$i}";
}
$client->bloomFilterInsert(
SCAN_KEY,
$insertData,
[OptionalParams::CAPACITY => $capacity, OptionalParams::ERROR => 0.01]
);
$bloomFilter = $factory->createBloomFilter(SCAN_KEY);
$bloomFilter->copy(TARGET_SCAN_KEY);
$multiExists = $client->bloomFilterMultiExists(TARGET_SCAN_KEY, ...$insertData);
$nonExistentKey = [];
foreach ($multiExists as $key => $exist) {
if ($exist === false) {
$nonExistentKey[] = $insertData[$key];
}
}
if (empty($nonExistentKey)) {
echo "all items were copied" . PHP_EOL;
} else {
echo count($nonExistentKey) . " were not copied:" . PHP_EOL;
var_dump($nonExistentKey);
}
$client->del(SCAN_KEY);
$client->del(TARGET_SCAN_KEY);