|
| 1 | +// EXAMPLE: cms_tutorial |
| 2 | +<?php |
| 3 | + |
| 4 | +require 'vendor/autoload.php'; |
| 5 | + |
| 6 | +use Predis\Client as PredisClient; |
| 7 | + |
| 8 | +class DtCmsTest |
| 9 | +// REMOVE_START |
| 10 | +extends PredisTestCase |
| 11 | +// REMOVE_END |
| 12 | +{ |
| 13 | + public function testDtCms() { |
| 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 cms |
| 26 | + $res1 = $r->cmsinitbyprob('bikes:profit', 0.001, 0.002); |
| 27 | + echo $res1 . PHP_EOL; |
| 28 | + // >>> OK |
| 29 | + |
| 30 | + $res2 = $r->cmsincrby('bikes:profit', 'Smoky Mountain Striker', 100); |
| 31 | + echo json_encode($res2) . PHP_EOL; |
| 32 | + // >>> [100] |
| 33 | + |
| 34 | + $res3 = $r->cmsincrby( |
| 35 | + 'bikes:profit', |
| 36 | + 'Rocky Mountain Racer', 200, |
| 37 | + 'Cloudy City Cruiser', 150 |
| 38 | + ); |
| 39 | + echo json_encode($res3) . PHP_EOL; |
| 40 | + // >>> [200,150] |
| 41 | + |
| 42 | + $res4 = $r->cmsquery('bikes:profit', 'Smoky Mountain Striker'); |
| 43 | + echo json_encode($res4) . PHP_EOL; |
| 44 | + // >>> [100] |
| 45 | + |
| 46 | + $res5 = $r->cmsinfo('bikes:profit'); |
| 47 | + echo $res5['width'] . ' ' . $res5['depth'] . ' ' . $res5['count'] . PHP_EOL; |
| 48 | + // >>> 2000 9 450 |
| 49 | + // STEP_END |
| 50 | + // REMOVE_START |
| 51 | + $this->assertEquals('OK', $res1); |
| 52 | + $this->assertEquals([100], $res2); |
| 53 | + $this->assertEquals([200, 150], $res3); |
| 54 | + $this->assertEquals([100], $res4); |
| 55 | + $this->assertEquals(2000, $res5['width']); |
| 56 | + $this->assertEquals(9, $res5['depth']); |
| 57 | + $this->assertEquals(450, $res5['count']); |
| 58 | + // REMOVE_END |
| 59 | + } |
| 60 | +} |
| 61 | + |
0 commit comments