1+ <?php
2+
3+ /**
4+ * @author Khoa Bui (khoaofgod) <[email protected] > https://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 \Redis \Config as RedisConfig ;
11+ use Phpfastcache \Drivers \Predis \Config as PredisConfig ;
12+
13+
14+ chdir (__DIR__ );
15+ require_once __DIR__ . '/../../vendor/autoload.php ' ;
16+ $ testHelper = new TestHelper ('Github issue #627 - Redis/Predis "prefix" option ' );
17+ $ redisInstance = CacheManager::getInstance ('Redis ' , new RedisConfig (['optPrefix ' => uniqid ('pfc ' , true ) . '_ ' ]));
18+ $ predisInstance = CacheManager::getInstance ('Predis ' , new PredisConfig (['optPrefix ' => uniqid ('pfc ' , true ) . '_ ' ]));
19+
20+ $ testHelper ->printInfoText ('Testing Redis 1/2 ' );
21+
22+ /**
23+ * Clear the cache to avoid
24+ * unexpected results
25+ */
26+ $ redisInstance ->clear ();
27+
28+ $ cacheKey = uniqid ('ck ' , true );
29+ $ string = uniqid ('pfc ' , true );
30+ $ testHelper ->printText ('Preparing test item... ' );
31+
32+ /**
33+ * Setup the cache item
34+ */
35+ $ cacheItem = $ redisInstance ->getItem ($ cacheKey );
36+ $ cacheItem ->set ($ string );
37+ $ redisInstance ->save ($ cacheItem );
38+ unset($ cacheItem );
39+ $ redisInstance ->detachAllItems ();
40+
41+ if ($ redisInstance ->getItem ($ cacheKey )->isHit ()){
42+ $ testHelper ->printPassText ('The cache item has been found in cache ' );
43+ }else {
44+ $ testHelper ->printFailText ('The cache item was not found in cache ' );
45+ }
46+
47+ $ testHelper ->printInfoText ('Testing Predis 2/2 ' );
48+
49+ /**
50+ * Clear the cache to avoid
51+ * unexpected results
52+ */
53+ $ predisInstance ->clear ();
54+
55+ $ cacheKey = uniqid ('ck ' , true );
56+ $ string = uniqid ('pfc ' , true );
57+ $ testHelper ->printText ('Preparing test item... ' );
58+
59+ /**
60+ * Setup the cache item
61+ */
62+ $ cacheItem = $ predisInstance ->getItem ($ cacheKey );
63+ $ cacheItem ->set ($ string );
64+ $ predisInstance ->save ($ cacheItem );
65+ unset($ cacheItem );
66+ $ predisInstance ->detachAllItems ();
67+
68+ if ($ predisInstance ->getItem ($ cacheKey )->isHit ()){
69+ $ testHelper ->printPassText ('The cache item has been found in cache ' );
70+ }else {
71+ $ testHelper ->printFailText ('The cache item was not found in cache ' );
72+ }
73+
74+
75+ $ testHelper ->terminateTest ();
0 commit comments