Git Product home page Git Product logo

bloomfilter's Introduction

bloom filter 过滤器

高效的挡住无效的请求和流量,可用于数据库查询前,过滤非命中查询。也可以用来防止redis缓存击穿。

WHY

安装

git clone https://github.com/luw2007/bloomfilter.git && \
    cd bloomfilter && \
    pip install -r requirements.txt && \
    python setup.py install

通过源代码安装项目依赖:

pyreBloom, hiredis(非必须)

git clone https://github.com/redis/hiredis.git /root/src/hiredis && \
    cd /root/src/hiredis && \
    make && make PREFIX=/usr install &&\
    ldconfig
git clone https://github.com/seomoz/pyreBloom /root/src/pyreBloom && \
    cd /root/src/pyreBloom && \
    python setup.py install

使用方法:

>>> from bloomfilter.base import BaseModel
>>> class TestModel(BaseModel):
...    PREFIX = "bf:test"
>>> t = TestModel()
>>> t.add('hello')
1
>>> t.extend(['hi', 'world'])
2
>>> t.contains('hi')
True
>>> t.delete()

可用方法:

extend, keys, contains, add, put, hashes, bits, delete

例子

请查看example目录

Q&A

  1. 运行报错, 缺少pyreBloom?
In [1]: from bloomfilter.base import BaseModel
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-3172e213138d> in <module>
----> 1 from bloomfilter.base import BaseModel

~/github/bloomfilter/bloomfilter/base.py in <module>
     52 import logging
     53 from six import PY3 as IS_PY3
---> 54 from pyreBloom import pyreBloom, pyreBloomException
     55
     56 from bloomfilter.utils import force_utf8

ModuleNotFoundError: No module named 'pyreBloom'

安装pyreBloom,pip install -r requirements.txt

bloomfilter's People

Contributors

luw2007 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.