Permalink
Browse files

Use transactions for saves, cleans and removes.

  • Loading branch information...
1 parent 599faed commit be56b80065381af8188650a7903a477671853274 @colinmollenhour committed Mar 25, 2012
Showing with 6 additions and 12 deletions.
  1. +5 −5 Cm/Cache/Backend/Redis.php
  2. +1 −7 README.md
@@ -165,7 +165,7 @@ public function save($data, $id, $tags = array(), $specificLifetime = false)
// Get list of tags previously assigned
$oldTags = explode(',', $this->_decodeData($this->_redis->hGet(self::PREFIX_KEY.$id, self::FIELD_TAGS)));
- $this->_redis->pipeline();
+ $this->_redis->pipeline()->multi();
// Set the data
$result = $this->_redis->hMSet(self::PREFIX_KEY.$id, array(
@@ -226,7 +226,7 @@ public function remove($id)
// Get list of tags for this id
$tags = explode(',', $this->_decodeData($this->_redis->hGet(self::PREFIX_KEY.$id, self::FIELD_TAGS)));
- $this->_redis->pipeline();
+ $this->_redis->pipeline()->multi();
// Remove data
$this->_redis->del(self::PREFIX_KEY.$id);
@@ -254,7 +254,7 @@ protected function _removeByNotMatchingTags($tags)
$ids = $this->getIdsNotMatchingTags($tags);
if($ids)
{
- $this->_redis->pipeline();
+ $this->_redis->pipeline()->multi();
// Remove data
$this->_redis->del( $this->_preprocessIds($ids));
@@ -276,7 +276,7 @@ protected function _removeByMatchingTags($tags)
$ids = $this->getIdsMatchingTags($tags);
if($ids)
{
- $this->_redis->pipeline();
+ $this->_redis->pipeline()->multi();
// Remove data
$this->_redis->del( $this->_preprocessIds($ids));
@@ -297,7 +297,7 @@ protected function _removeByMatchingAnyTags($tags)
{
$ids = $this->getIdsMatchingAnyTags($tags);
- $this->_redis->pipeline();
+ $this->_redis->pipeline()->multi();
if($ids)
{
View
@@ -12,6 +12,7 @@ Works with any Zend Framework project including all versions of Magento!
- Key expiry is handled automatically by Redis, and the cache is safe to use with the "allkeys-lru" maxmemory-policy config option.
- Supports unix socket connection for even better performance on a single machine.
- Supports configurable compression for memory savings. Can choose between gzip, lzf and snappy and can change configuration without flushing cache.
+ - Uses transactions to prevent race conditions between saves, cleans or removes causing unexpected results.
- Unit tested!
## INSTALLATION (Magento)
@@ -49,13 +50,6 @@ Works with any Zend Framework project including all versions of Magento!
</backend_options>
</cache>
-## KNOWN ISSUES
-
- - In very rare circumstances it may be possible for a race-condition to cause inconsistent tag data such as if one
- process is removing a cache entry as another is adding it. However, operations are pipelined to reduce these risks
- greatly and cached data is not subject to corruption. As far as I know the risk is no greater than with most other
- backends.
-
## RELATED / TUNING
- Automatic cleaning is optional and not necessary, but recommended in cases with frequently changing tags and keys or

0 comments on commit be56b80

Please sign in to comment.