File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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 ();
You can’t perform that action at this time.
0 commit comments