Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
implement ClearByNamespace interface in Redis adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
aimfeld committed Jan 14, 2016

Verified

This commit was signed with the committer’s verified signature. The key has expired.
kylekurz Kyle Kurz
1 parent 5928bb3 commit a06560d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Storage/Adapter/Redis.php
Original file line number Diff line number Diff line change
@@ -13,13 +13,15 @@
use RedisException as RedisResourceException;
use stdClass;
use Traversable;
use Zend\Cache\Storage\ClearByNamespaceInterface;
use Zend\Cache\Storage\ClearByPrefixInterface;
use Zend\Cache\Exception;
use Zend\Cache\Storage\Capabilities;
use Zend\Cache\Storage\FlushableInterface;
use Zend\Cache\Storage\TotalSpaceCapableInterface;

class Redis extends AbstractAdapter implements
ClearByNamespaceInterface,
ClearByPrefixInterface,
FlushableInterface,
TotalSpaceCapableInterface
@@ -411,6 +413,31 @@ public function flush()
}
}

/* ClearByNamespaceInterface */

/**
* Remove items of given namespace
*
* @param string $namespace
* @return bool
*/
public function clearByNamespace($namespace)
{
$redis = $this->getRedisResource();

$namespace = (string) $namespace;
if ($namespace === '') {
throw new Exception\InvalidArgumentException('No namespace given');
}

$options = $this->getOptions();
$prefix = $namespace . $options->getNamespaceSeparator();

$redis->delete($redis->keys($prefix . '*'));

return true;
}

/* ClearByPrefixInterface */

/**

0 comments on commit a06560d

Please sign in to comment.