Skip to content

Commit 6b21471

Browse files
DOC-5678 PHP cuckoo filter examples
1 parent 0ec53ec commit 6b21471

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// EXAMPLE: cuckoo_tutorial
2+
<?php
3+
4+
require 'vendor/autoload.php';
5+
6+
use Predis\Client as PredisClient;
7+
8+
class DtCuckooTest
9+
// REMOVE_START
10+
extends PredisTestCase
11+
// REMOVE_END
12+
{
13+
public function testDtCuckoo() {
14+
$r = new PredisClient([
15+
'scheme' => 'tcp',
16+
'host' => '127.0.0.1',
17+
'port' => 6379,
18+
'password' => '',
19+
'database' => 0,
20+
]);
21+
// REMOVE_START
22+
$r->flushall();
23+
// REMOVE_END
24+
25+
// STEP_START cuckoo
26+
$res1 = $r->cfreserve('bikes:models', 1000000);
27+
echo $res1 . PHP_EOL;
28+
// >>> OK
29+
30+
$res2 = $r->cfadd('bikes:models', 'Smoky Mountain Striker');
31+
echo $res2 . PHP_EOL;
32+
// >>> 1
33+
34+
$res3 = $r->cfexists('bikes:models', 'Smoky Mountain Striker');
35+
echo $res3 . PHP_EOL;
36+
// >>> 1
37+
38+
$res4 = $r->cfexists('bikes:models', 'Terrible Bike Name');
39+
echo $res4 . PHP_EOL;
40+
// >>> 0
41+
42+
$res5 = $r->cfdel('bikes:models', 'Smoky Mountain Striker');
43+
echo $res5 . PHP_EOL;
44+
// >>> 1
45+
// STEP_END
46+
// REMOVE_START
47+
$this->assertEquals('OK', $res1);
48+
$this->assertEquals(1, $res2);
49+
$this->assertEquals(1, $res3);
50+
$this->assertEquals(0, $res4);
51+
$this->assertEquals(1, $res5);
52+
// REMOVE_END
53+
}
54+
}
55+

0 commit comments

Comments
 (0)