定制 fuliang/bloom-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fuliang/bloom-filter

最新稳定版本:v0.0.2

Composer 安装命令:

composer require fuliang/bloom-filter

包简介

基于redis实现的布隆过滤器

README 文档

README

安装

composer require fuliang/bloom-filter

使用

第一步

<?php
namespace Fuliang\BloomFilter;

use Redis;
/**
 * 重复内容过滤器
 * 该布隆过滤器总位数为2^32位, 判断条数为2^30条. hash函数最优为3个.(能够容忍最多的hash函数个数)
 * 使用的三个hash函数为
 * BKDR, SDBM, JSHash
 *
 * 注意, 在存储的数据量到2^30条时候, 误判率会急剧增加, 因此需要定时判断过滤器中的位为1的的数量是否超过50%, 超过则需要清空.
 */
class FilterRepeatedComments extends BloomFilterRedis
{
    /**
     * 表示判断重复内容的过滤器
     * @var string
     */
    protected string  $bucket = 'rptc';

    protected array $hashFunction = ['BKDRHash', 'SDBMHash', 'JSHash'];

    protected function getRedisClient(): Redis
    {
        return new YourRedis; // 假设这里你已经连接好了
    }
}

第二步

<?php
require_once 'vendor\autoload.php';
use Fuliang\BloomFilter\FilterRepeatedComments;

$bf = new FilterRepeatedComments();
$bf->add('item1');
$bf->add('item2');

$bf->exists('item1'); //true
$bf->exists('item2'); //true

$bf->delete('item1');
$bf->exists('item1'); //false

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-29