Browse Source

Update RedisEngine to psr16 compatible implementation

Mark Story 7 years ago
parent
commit
8cf009278f

+ 1 - 1
src/Cache/Cache.php

@@ -317,7 +317,7 @@ class Cache
      *
      * @param string $key Identifier for the data
      * @param string $config optional name of the configuration to use. Defaults to 'default'
-     * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
+     * @return mixed The cached data, or null if the data doesn't exist, has expired, or if there was an error fetching it
      */
     public static function read(string $key, string $config = 'default')
     {

+ 6 - 2
src/Cache/Engine/RedisEngine.php

@@ -127,9 +127,12 @@ class RedisEngine extends CacheEngine
      *
      * @param string $key Identifier for the data
      * @param mixed $value Data to be cached
+     * @param null|int|\DateInterval $ttl Optional. The TTL value of this item. If no value is sent and
+     *   the driver supports TTL then the library may set a default value
+     *   for it or let the driver take care of that.
      * @return bool True if the data was successfully cached, false on failure
      */
-    public function write(string $key, $value): bool
+    public function set($key, $value, $ttl = null)
     {
         $key = $this->_key($key);
 
@@ -149,9 +152,10 @@ class RedisEngine extends CacheEngine
      * Read a key from the cache
      *
      * @param string $key Identifier for the data
+     * @param mixed $default Default value to return if the key does not exist.
      * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
      */
-    public function read(string $key)
+    public function get($key, $default = null)
     {
         $key = $this->_key($key);
 

+ 4 - 4
tests/TestCase/Cache/Engine/RedisEngineTest.php

@@ -392,17 +392,17 @@ class RedisEngineTest extends TestCase
         ]);
 
         Cache::write('some_value', 'cache1', 'redis');
-        $result = Cache::clear(true, 'redis');
+        $result = Cache::clear('redis');
         $this->assertTrue($result);
-        $this->assertEquals('cache1', Cache::read('some_value', 'redis'));
+        $this->assertFalse(Cache::read('some_value', 'redis'));
 
         Cache::write('some_value', 'cache2', 'redis2');
-        $result = Cache::clear(false, 'redis');
+        $result = Cache::clear('redis');
         $this->assertTrue($result);
         $this->assertFalse(Cache::read('some_value', 'redis'));
         $this->assertEquals('cache2', Cache::read('some_value', 'redis2'));
 
-        Cache::clear(false, 'redis2');
+        Cache::clear('redis2');
     }
 
     /**