Skip to content

Commit

Permalink
去除布隆过滤器
Browse files Browse the repository at this point in the history
  • Loading branch information
yymou committed Dec 25, 2020
1 parent 56befb8 commit f89f556
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
],
"autoload": {
"psr-4": {
"Slink\\": "src/"
"Slink\\": "src/",
"Test\\": "test/"
}
},
"require": {
"php": ">=7.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.4"
}
}
}
13 changes: 3 additions & 10 deletions src/process/Slink.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ public function start()
//检查短链是否存在
private function checkLink() : bool
{
$is_exist = Bf::getInstance()->exists($this->originLink);

//如果存在查询具体数据
if ($is_exist) {
$this->shortLink = Redis::getInstance()->getShort(urlencode($this->originLink));
if (!empty($this->shortLink)) {
return true;
}
$this->shortLink = Redis::getInstance()->getShort(urlencode($this->originLink));
if (!empty($this->shortLink)) {
return true;
}
return false;
}
Expand All @@ -75,8 +70,6 @@ private function saveRelation() : void
Redis::getInstance()->setLinkHash($this->save_alias, $this->shortLink, urlencode($this->originLink));
//设置origin-short的缓存
Redis::getInstance()->saveOriginlink(urlencode($this->originLink), $this->shortLink);
//添加到布隆过滤器
Bf::getInstance()->add($this->originLink);
}

}
Expand Down
20 changes: 20 additions & 0 deletions test/AppTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

class AppTest extends \PHPUnit\Framework\TestCase
{
public function Test() {
//生成短连接测试
Slink\App::getInstance()->setCommonRedis([
'hostname' => '127.0.0.1',
'password' => '',
'port' => '6379',
'timeout' => '5'
]);

Slink\App::getInstance()->setRedisPrefix('slink:test');

Slink\App::getInstance()->setSlinkLen(7);

$this->assertContainsOnly('string', Slink\App::getInstance()->getSlink('https://www.baidu.com'));
}
}

0 comments on commit f89f556

Please sign in to comment.