Beispiel #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();
 }
Beispiel #2
0
 public function testScripts()
 {
     $this->assertNull($this->credis->evalSha('1111111111111111111111111111111111111111'));
     $this->assertEquals(3, $this->credis->eval('return 3'));
     $this->assertEquals('09d3822de862f46d784e6a36848b4f0736dda47a', $this->credis->script('load', 'return 3'));
     $this->assertEquals(3, $this->credis->evalSha('09d3822de862f46d784e6a36848b4f0736dda47a'));
     $this->credis->set('foo', 'FOO');
     $this->assertEquals('FOOBAR', $this->credis->eval("return redis.call('get', KEYS[1])..ARGV[1]", 'foo', 'BAR'));
     $this->assertEquals(array(1, 2, 'three'), $this->credis->eval("return {1,2,'three'}"));
     try {
         $this->credis->eval('this-is-not-lua');
         $this->fail('Expected exception on invalid script.');
     } catch (CredisException $e) {
     }
 }