forked from Boris-code/feapder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dedup.py
More file actions
56 lines (38 loc) · 1.26 KB
/
Copy pathtest_dedup.py
File metadata and controls
56 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from feapder.dedup import Dedup
data = {"xxx": 123, "xxxx": "xxxx"}
datas = ["xxx", "bbb"]
def test_MemoryFilter():
dedup = Dedup(Dedup.MemoryFilter) # 表名为test 历史数据3秒有效期
# 逐条去重
assert dedup.add(data) == 1
assert dedup.get(data) == 1
# 批量去重
assert dedup.add(datas) == [1, 1]
assert dedup.get(datas) == [1, 1]
def test_ExpireFilter():
dedup = Dedup(
Dedup.ExpireFilter, expire_time=10, redis_url="redis://@localhost:6379/0"
)
# 逐条去重
assert dedup.add(data) == 1
assert dedup.get(data) == 1
# 批量去重
assert dedup.add(datas) == [1, 1]
assert dedup.get(datas) == [1, 1]
def test_BloomFilter():
dedup = Dedup(Dedup.BloomFilter, redis_url="redis://@localhost:6379/0")
# 逐条去重
assert dedup.add(data) == 1
assert dedup.get(data) == 1
# 批量去重
assert dedup.add(datas) == [1, 1]
assert dedup.get(datas) == [1, 1]
def test_filter():
dedup = Dedup(Dedup.BloomFilter, redis_url="redis://@localhost:6379/0")
# 制造已存在数据
datas = ["xxx", "bbb"]
dedup.add(datas)
# 过滤掉已存在数据 "xxx", "bbb"
datas = ["xxx", "bbb", "ccc"]
dedup.filter_exist_data(datas)
assert datas == ["ccc"]