kalaspuff / redis-cache-zend-framework

🗄 Redis cache backend for Zend Framework with support for tags. Uses PHP module phpredis. [not actively maintained]
BSD 3-Clause "New" or "Revised" License
44 stars 30 forks source link

non-tag code in save() is never followed #8

Open thompsa opened 8 years ago

thompsa commented 8 years ago
 public function save($data, $id, $tags = array(), $specificLifetime = false)
    {
        if (!$this->_redis)
            return false;
        $lifetime = $this->getLifetime($specificLifetime);
        if (!$tags || !count($tags))
            $tags = array('');
        if (is_string($tags))
            $tags = array($tags);
        if (!count($tags)) {
        ...

In this block of code if tags is not set or an empty array it will always be set to an array containing one empty string. This means that the code block for set/setex is never followed when no tags are present.

Change to initialising it to an empty array. This is still slightly redundant as the function declaration has a default value for $tags.

--- Redis.php
+++ Redis.php
@@ -184,7 +184,7 @@ 
         $lifetime = $this->getLifetime($specificLifetime);

         if (!$tags || !count($tags))
-            $tags = array('');
+            $tags = array();
         if (is_string($tags))
             $tags = array($tags);