Skip to content

Commit 0b8a805

Browse files
DOC-5678 PHP hyperloglog examples
1 parent f0d97a8 commit 0b8a805

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

local_examples/php/DtHllTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// EXAMPLE: hll_tutorial
2+
<?php
3+
4+
require 'vendor/autoload.php';
5+
6+
use Predis\Client as PredisClient;
7+
8+
class DtHllTest
9+
// REMOVE_START
10+
extends PredisTestCase
11+
// REMOVE_END
12+
{
13+
public function testDtHll() {
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 pfadd
26+
$res1 = $r->pfadd('bikes', ['Hyperion', 'Deimos', 'Phoebe', 'Quaoar']);
27+
echo $res1 . PHP_EOL;
28+
// >>> 1
29+
30+
$res2 = $r->pfcount('bikes');
31+
echo $res2 . PHP_EOL;
32+
// >>> 4
33+
34+
$res3 = $r->pfadd('commuter_bikes', ['Salacia', 'Mimas', 'Quaoar']);
35+
echo $res3 . PHP_EOL;
36+
// >>> 1
37+
38+
$res4 = $r->pfmerge('all_bikes', 'bikes', 'commuter_bikes');
39+
echo $res4 . PHP_EOL;
40+
// >>> OK
41+
42+
$res5 = $r->pfcount('all_bikes');
43+
echo $res5 . PHP_EOL;
44+
// >>> 6
45+
// STEP_END
46+
// REMOVE_START
47+
$this->assertEquals(1, $res1);
48+
$this->assertEquals(4, $res2);
49+
$this->assertEquals(1, $res3);
50+
$this->assertEquals('OK', $res4);
51+
$this->assertEquals(6, $res5);
52+
// REMOVE_END
53+
}
54+
}
55+

0 commit comments

Comments
 (0)