kalaspuff/redis-cache-zend-framework

non-tag code in save() is never followed

thompsa opened this issue · 0 comments

 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);