Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation of Redis5 BloomFilter under mac and how to use it with python

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail the "installation of Redis5 BloomFilter under mac and how to use it with python". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "installation of Redis5 BloomFilter under mac and how to use it with python" can help you solve your doubts.

Installation and use of Bloom filter

Install and use Bloom filter (BloomFilter) on Redis 5.x on Centos7

1 enter the redis installation directory: cd / usr/local/redis-5.0.42. Download plug-in: git clone https://github.com/RedisBloom/RedisBloom.git # https://github.com/RedisBloom/RedisBloom if slow, you can use the public network to access 3. Enter the plug-in directory: cd redisbloom/ (RedisBloom before renaming) 4. Execution: make5. Modify redis.conf and add configuration: loadmodule / usr/local/redis-5.0.4/redisbloom/redisbloom.so6. Start redis: src/redis-server. / redis.conf7. Connect the client: src/redis-cli-p 6379 8. Test, execute successively: bf.add users francis bf.exists users francis 9. For more information, please refer to https://oss.redislabs.com/redisbloom/

The use of python

1. The first method is to connect to redis using native statements using the

From redis import StrictRedisfrom django.conf import settingsclass BfRedis: def _ init__ (self, db, host=settings.BF_REDIS_HOST, port=settings.BF_REDIS_PORT, password=settings.BF_REDIS_PASSWORD): self.client = StrictRedis (db=db, host=host, port=port, password=password) def bf_init (self, key: str, error_rate: float (), size: int): res = self.client.execute_command ('BF.RESERVE', key, error_rate Size) return res def bf_exists (self, key, value): res = self.client.execute_command ('BF.exists', key, value) return res def bf_add (self, key, value): return self.client.execute_command (' BF.add', key, value) def bf_local_init (self, task_id, error_rate=0.0001) Size=10000): "key = fancibf{ task_id}'if self.client.exists (key): return True res = self.bf_init (key, error_rate, size) return res def bf_local_add (self, task_id, value): key = fancibf{ task_id} 'res = self.bf_add (key) Value) return res def bf_local_exists (self, task_id, value): key = fancibf _ {task_id} 'res = self.bf_exists (key, value) return res def bf_local_del (self, task_id): key = fancibf{ task_id}' res = self.client.delete (key) return res# bf_redis = CrawlRedisClient (0)

Using the tool module of python

Python2 installation: pip install pybloompython3 installation: pip install pybloom-live

Demo

From pybloom import BloomFilter, ScalableBloomFilterbf = BloomFilter (capacity=10000, error_rate=0.001) bf.add ('test') print' test' in bfsbf = ScalableBloomFilter (mode=ScalableBloomFilter.SMALL_SET_GROWTH) sbf.add ('dddd') print' ddd' in sbf

BloomFilter is a constant volume filter, error_rate means that the maximum false alarm rate is 0.1%, while ScalableBloomFilter is an indefinite capacity Bloom filter, which can constantly add elements. The add method adds an element, returns true if the element is already in the Bloom filter, and adds the element to the filter if it no longer returns fasle. To determine whether an element is in the filter, you only need to use the in operator.

After reading this, the article "Redis5 BloomFilter installation under mac and how to use it with python" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report