Пример #1
0
 /**
  * @param array $tags
  */
 protected function _removeByMatchingAnyTags($tags)
 {
     if ($this->_useLua) {
         $scriptSha1 = $this->_notMatchingTags ? self::LUA_CLEAN_NMT_SH1 : self::LUA_CLEAN_SH1;
         $pTags = $this->_preprocessTagIds($tags);
         $sArgs = array(self::PREFIX_KEY, self::SET_TAGS, self::SET_IDS);
         if (!$this->_redis->evalSha($scriptSha1, $pTags, $sArgs)) {
             $script = "local keysToDel = redis.call('SUNION', unpack(KEYS)) " . "for _, keyname in ipairs(keysToDel) do " . "redis.call('DEL', ARGV[1]..keyname) " . ($this->_notMatchingTags ? "redis.call('SREM', ARGV[3], keyname) " : "") . "end " . "redis.call('DEL', unpack(KEYS)) " . "redis.call('SREM', ARGV[2], unpack(KEYS)) " . "return true";
             $this->_redis->eval($script, $pTags, $sArgs);
         }
         return;
     }
     $ids = $this->getIdsMatchingAnyTags($tags);
     $this->_redis->pipeline()->multi();
     if ($ids) {
         // Remove data
         $this->_redis->del($this->_preprocessIds($ids));
         // Remove ids from list of all ids
         if ($this->_notMatchingTags) {
             $this->_redis->sRem(self::SET_IDS, $ids);
         }
     }
     // Remove tag id lists
     $this->_redis->del($this->_preprocessTagIds($tags));
     // Remove tags from list of tags
     $this->_redis->sRem(self::SET_TAGS, $tags);
     $this->_redis->exec();
 }
Пример #2
0
 /**
  * Public for testing/import purposes only.
  *
  * @param $id
  * @param $data
  * @param $lifetime
  * @throws Exception
  */
 public function _writeRawSession($id, $data, $lifetime)
 {
     if (!$this->_useRedis) {
         throw new Exception('Not connected to redis!');
     }
     $sessionId = 'sess_' . $id;
     $this->_redis->pipeline()->select($this->_dbNum)->hMSet($sessionId, array('data' => $this->_encodeData($data), 'lock' => 0))->hIncrBy($sessionId, 'writes', 1)->expire($sessionId, min($lifetime, 2592000))->exec();
 }
Пример #3
0
 public function testTransaction()
 {
     $reply = $this->credis->multi()->incr('foo')->incr('bar')->exec();
     $this->assertEquals(array(1, 1), $reply);
     $reply = $this->credis->pipeline()->multi()->incr('foo')->incr('bar')->exec();
     $this->assertEquals(array(2, 2), $reply);
     $reply = $this->credis->multi()->pipeline()->incr('foo')->incr('bar')->exec();
     $this->assertEquals(array(3, 3), $reply);
     $reply = $this->credis->multi()->set('a', 3)->lpop('a')->exec();
     $this->assertEquals(2, count($reply));
     $this->assertEquals(TRUE, $reply[0]);
     $this->assertFalse($reply[1]);
 }
Пример #4
0
 /**
  * Log a hit or a miss to Redis.
  *
  * @param string $fullActionName
  * @param bool $hit
  */
 public function logRequest($fullActionName, $hit)
 {
     try {
         $redis = new Credis_Client($this->config->server, NULL, 0.1);
         $redis->pipeline();
         if ($this->config->db) {
             $redis->select($this->config->db);
         }
         $redis->incr('diehard:' . ($hit ? 'hit' : 'miss'));
         if ($fullActionName && $this->config->is('full_action_name')) {
             $redis->incr('diehard:' . $fullActionName . ':' . ($hit ? 'hit' : 'miss'));
         }
         $redis->exec();
         $redis->close();
     } catch (Exception $e) {
         Mage::log($e->getMessage(), Zend_Log::ERR, 'diehard_counter.log');
     }
 }
Пример #5
0
 /**
  * @param array $tags
  */
 protected function _removeByMatchingAnyTags($tags)
 {
     $ids = $this->getIdsMatchingAnyTags($tags);
     $this->_redis->pipeline()->multi();
     if ($ids) {
         // Remove data
         $this->_redis->del($this->_preprocessIds($ids));
         // Remove ids from list of all ids
         if ($this->_notMatchingTags) {
             $this->_redis->sRem(self::SET_IDS, $ids);
         }
     }
     // Remove tag id lists
     $this->_redis->del($this->_preprocessTagIds($tags));
     // Remove tags from list of tags
     $this->_redis->sRem(self::SET_TAGS, $tags);
     $this->_redis->exec();
 }
Пример #6
0
 /**
  * Public for testing/import purposes only.
  *
  * @param $id
  * @param $data
  * @param $lifetime
  * @throws \Exception
  */
 public function _writeRawSession($id, $data, $lifetime)
 {
     $sessionId = 'sess_' . $id;
     $this->_redis->pipeline()->select($this->_dbNum)->hMSet($sessionId, array('data' => $this->_encodeData($data), 'lock' => 0))->hIncrBy($sessionId, 'writes', 1)->expire($sessionId, min($lifetime, $this->_maxLifetime))->exec();
 }