1 | <?php |
||
2 | |||
3 | namespace Aimeos\Base\Cache; |
||
4 | |||
5 | |||
6 | /** |
||
7 | * Real test against server for class \Aimeos\Base\Cache\Redis. |
||
8 | * |
||
9 | * @license LGPLv3, http://www.gnu.org/licenses/lgpl.html |
||
10 | * @copyright Metaways Infosystems GmbH, 2014 |
||
11 | * @copyright Aimeos (aimeos.org), 2015-2025 |
||
12 | */ |
||
13 | class RedisServerTest extends \PHPUnit\Framework\TestCase |
||
14 | { |
||
15 | public function testRun() |
||
16 | { |
||
17 | if( !class_exists( '\\Predis\\Client' ) ) { |
||
18 | $this->markTestSkipped( 'Predis library not available' ); |
||
19 | } |
||
20 | |||
21 | try |
||
22 | { |
||
23 | $predis = new \Predis\Client(); |
||
24 | |||
25 | $client = new \Aimeos\Base\Cache\Redis( [], $predis ); |
||
26 | $client->clear(); |
||
27 | } |
||
28 | catch( \Exception $e ) |
||
29 | { |
||
30 | $this->markTestSkipped( 'Predis server not available' ); |
||
31 | } |
||
32 | |||
33 | |||
34 | $client->set( 'arc-single-key', 'single-value' ); |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||
35 | $valSingle = $client->get( 'arc-single-key' ); |
||
36 | $valNone = $client->get( 'arc-no-key', 'none' ); |
||
37 | |||
38 | $client->set( 'arc-mkey3', 'mvalue3', '2000-01-01 00:00:00' ); |
||
39 | $valExpired = $client->get( 'arc-mkey3' ); |
||
40 | |||
41 | $client->setMultiple( array( 'arc-mkey1' => 'mvalue1', 'arc-mkey2' => 'mvalue2' ) ); |
||
42 | $listNormal = $client->getMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
43 | |||
44 | $pairs = array( 'arc-mkey4' => 'mvalue4', 'arc-mkey5' => 'mvalue5' ); |
||
45 | $tags = array( 'arc-mkey4' => 'arc-mtag4', 'arc-mkey5' => 'arc-mtag5' ); |
||
46 | $expires = array( 'arc-mkey5' => '2000-01-01 00:00:00' ); |
||
47 | $client->setMultiple( $pairs, $expires, $tags ); |
||
48 | $listExpired = $client->getMultiple( array( 'arc-mkey4', 'arc-mkey5' ) ); |
||
49 | |||
50 | $client->deleteByTags( array( 'arc-mtag4', 'arc-mtag5' ) ); |
||
51 | $listDelByTags = $client->getMultiple( array( 'arc-mkey4', 'arc-mkey5' ) ); |
||
52 | |||
53 | $client->deleteMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
54 | $listDelList = $client->getMultiple( array( 'arc-mkey1', 'arc-mkey2' ) ); |
||
55 | |||
56 | $client->delete( 'arc-single-key' ); |
||
57 | $valDelSingle = $client->get( 'arc-single-key' ); |
||
58 | |||
59 | |||
60 | $this->assertEquals( 'single-value', $valSingle ); |
||
61 | $this->assertEquals( 'none', $valNone ); |
||
62 | $this->assertEquals( null, $valExpired ); |
||
63 | $this->assertEquals( array( 'arc-mkey1' => 'mvalue1', 'arc-mkey2' => 'mvalue2' ), $listNormal ); |
||
64 | $this->assertEquals( array( 'arc-mkey4' => 'mvalue4' ), $listExpired ); |
||
65 | $this->assertEquals( [], $listDelByTags ); |
||
66 | $this->assertEquals( [], $listDelList ); |
||
67 | $this->assertEquals( null, $valDelSingle ); |
||
68 | } |
||
69 | } |
||
70 |