Skip to content

Commit e507a8b

Browse files
committed
Added test for custom predis client
1 parent cdfaf01 commit e507a8b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/PredisCustomClient.test.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* @author Khoa Bui (khoaofgod) <[email protected]> http://www.phpfastcache.com
5+
* @author Georges.L (Geolim4) <[email protected]>
6+
*/
7+
8+
use Phpfastcache\CacheManager;
9+
use Phpfastcache\Helper\TestHelper;
10+
use Phpfastcache\Drivers\Predis\Config as PredisConfig;
11+
use Predis\Client as PredisClient;
12+
13+
chdir(__DIR__);
14+
require_once __DIR__ . '/../vendor/autoload.php';
15+
$testHelper = new TestHelper('Predis custom client');
16+
17+
try{
18+
$predisClient = new PredisClient([
19+
'host' => '127.0.0.1',
20+
'port' => 6379,
21+
'password' => null,
22+
'database' => 0,
23+
]);
24+
$predisClient->connect();
25+
26+
$cacheInstance = CacheManager::getInstance('Predis', (new PredisConfig())->setPredisClient($predisClient));
27+
$cacheKey = 'predisCustomClient';
28+
$cacheItem = $cacheInstance->getItem($cacheKey);
29+
$cacheItem->set(1337);
30+
$cacheInstance->save($cacheItem);
31+
$cacheInstance->detachAllItems();
32+
unset($cacheItem);
33+
if($cacheInstance->getItem($cacheKey)->get() === 1337){
34+
$testHelper->printPassText('Successfully written and read data from outside Predis client');
35+
}else{
36+
$testHelper->printFailText('Error writing or reading data from outside Predis client');
37+
}
38+
}catch (\RedisException $e){
39+
$testHelper->printFailText('A Predis exception occurred: ' . $e->getMessage());
40+
}
41+
42+
$testHelper->terminateTest();

0 commit comments

Comments
 (0)