Python库,它实现了一个重新备份的Bloom过滤器。
ibloom的Python项目详细描述
伊布卢姆
这是pyreBloom-ng的分支,pyreBloom ng是一个python库,它实现了一个Redis支持的Bloom过滤器。在
布鲁姆真的很强大。但它是设置.py测试和试验台/基准.py都过时了,回购的最后承诺是4年前。在
基于pyreBloom ng ng并添加了python3的str支持,避免了烦人的b'some_key'
安装
先决条件
ibloom
需要hiredis
库、Cython
和{
hiredis
# Mac brew install hiredis # ubuntu apt-get install libhiredis-dev # From source: git clone https://github.com/redis/hiredis cd hiredis && make && sudo make install
^{pr2}$Cython
启动
初始化实例
fromibloomimportIBloomib=IBloom('ibloomI',1000,0.01,'127.0.0.1',6383)
或者
fromibloomimportIBloomib_n=IBloom(key='ibloomN',capacity=1000,error=0.01,host='127.0.0.1',port=6383)
检查基本信息
# You can find out how many bits this will theoretically consume>>>ib.bits9585# And how many hashes are needed to satisfy the false positive rate>>>ib.hashes7# find all available bloom filter keys>>>ib.keys()['ibloomI.0']
添加数据
添加所有提供的
# Add one value at a time (slow)>>>ib.add('first')True# Or use batch operations (faster).>>>ib.update([f'{x}'forxinrange(5)])5# Alternative: ib += data, but this will return nothing>>>ib+=[f'{x+5}'forxinrange(5)]
仅在不存在时添加
# will first get the difference, and then update them to redis, and return them>>>ib.update_difference(['5','6','7','8','9','10'])['10']
检查钥匙是否存在
找到一个
# Test one value at a time (slow).# . in ...>>>'first'inibTrue# ...contains(.)>>>ib.contains('first')True
查找多个
# Use batch operations (faster).# Note: ibloom.intersection() returns a list of values# which are found in a Bloom filter. It makes sense when# you consider it a set-like operation.>>>ib.intersection(['3','4','5','6'])['3','4','5','6']# Alternative: ib & [b'3', b'4', b'5', b'6']>>>ib&['3','4','5','6','9','10']['3','4','5','6','9']
查找不存在
>>>ib.difference(['5','6','7','8','9','10'])['10']# not recommended, maybe update in the future# Alternative: ib ^ ['5', '6', '7', '8', '9', '10']>>>ib^['5','6','7','8','9','10']['10']
删除bloom键
# delete selfib.delete()
标签:
- 项目
标签: