Skip to content

Commit

Permalink
flat output range and zInter
Browse files Browse the repository at this point in the history
  • Loading branch information
mobilesikuda committed Jan 23, 2025
1 parent ac15197 commit 11e8c7c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
35 changes: 35 additions & 0 deletions predis.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

//debug function
require "vendor/predis/predis/src/Autoloader.php";
Predis\Autoloader::register();

$client = new Predis\Client([
'scheme' => 'tcp',
'host' => 'localhost',
'port' => 6379,
]);

$client->connect();
$client->flushAll();

echo $client->zAdd('conditions:param1', 1000, 'event:event1').'<br/>';

Check failure on line 16 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;.&quot;; 0 found

Check failure on line 16 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;.&quot;; 0 found

echo $client->zAdd('conditions:param1', 2000, 'event:event2').'<br/>';

Check failure on line 18 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;.&quot;; 0 found

Check failure on line 18 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;.&quot;; 0 found
echo $client->zAdd('conditions:param2', 2000, 'event:event2').'<br/>';

Check failure on line 19 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space before &quot;.&quot;; 0 found

Check failure on line 19 in predis.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected at least 1 space after &quot;.&quot;; 0 found

echo $client->zAdd('conditions:param1', 3000, 'event:event3').'<br/>';
echo $client->zAdd('conditions:param2', 3000, 'event:event3').'<br/>';

var_dump($client->zRevRangeByScore('conditions:param1', 5000, 0, ['WITHSCORES'=>true])); //
echo '<br/>';

//var_dump($clienredis->zRangeByScore('conditions:param1', 0, 5000, ['WITHSCORES'=>true])); //
//echo '<br/>';

//var_dump($client->zUnion(['conditions:param1', 'conditions:param2'], NULL, 'max']));
$result_inter = $client->zInter(['conditions:param1', 'conditions:param2'], [], 'min', true);
arsort($result_inter);
var_dump($result_inter);

$client->disconnect();
27 changes: 15 additions & 12 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ public function runApp() {

$client->connect();
$client->flushAll();

echo $client->zAdd('conditions:param1', 1000, '1').'<br/>';
echo $client->zAdd('event:event1', 1000, 'ok').'<br/>';

echo $client->zAdd('conditions:param1', 2000, 2).'<br/>';
echo $client->zAdd('conditions:param2', 2000, 2).'<br/>';
echo $client->zAdd('event:event1', 2000, 'ok').'<br/>';
$client->zAdd('conditions:param1', 1000, 'event:event1').'<br/>';

echo $client->zAdd('conditions:param1', 3000, 1).'<br/>';
echo $client->zAdd('conditions:param2', 3000, 2).'<br/>';
echo $client->zAdd('event:event1', 3000, 'ok').'<br/>';
$client->zAdd('conditions:param1', 2000, 'event:event2').'<br/>';
$client->zAdd('conditions:param2', 2000, 'event:event2').'<br/>';

$client->zAdd('conditions:param1', 3000, 'event:event3').'<br/>';
$client->zAdd('conditions:param2', 3000, 'event:event3').'<br/>';

echo "zRevRangeByScore('conditions:param1', 5000, 0, ['WITHSCORES'=>true])<br/> = ";
var_dump($client->zRevRangeByScore('conditions:param1', 5000, 0, ['WITHSCORES'=>true])); //
echo '<br/>';
echo '<br/>';

//var_dump($client->zRangeByScore('conditions:param1', 0, 5000, ['WITHSCORES'=>true])); //
//var_dump($clienredis->zRangeByScore('conditions:param1', 0, 5000, ['WITHSCORES'=>true])); //
//echo '<br/>';

var_dump($client->zUnion(['conditions:param1', 'conditions:param2']));

//var_dump($client->zUnion(['conditions:param1', 'conditions:param2'], NULL, 'max']));
echo "zInter(['conditions:param1', 'conditions:param2'], [], 'min', true) and sort <br/> = ";
$result_inter = $client->zInter(['conditions:param1', 'conditions:param2'], [], 'min', true);
arsort($result_inter);
var_dump($result_inter);

$client->disconnect();
}
}
Expand Down

0 comments on commit 11e8c7c

Please sign in to comment.