mdlayher/php-bloomd

此包已被放弃,不再维护。未建议替代包。

PHP 5.4+ 用于与 bloomd 服务器交互的类。MIT 许可证。

1.0 2013-11-11 21:11 UTC

This package is not auto-updated.

Last update: 2020-01-20 07:00:41 UTC


README

PHP 5.4+ 用于与 bloomd 服务器交互的类 (https://github.com/armon/bloomd)。MIT 许可证。

安装

php-bloomd 可以通过 Composer 安装。将 "mdlayher/php-bloomd": "dev-master" 添加到 composer.json 文件的 require 部分,然后运行 composer install

测试

php-bloomd 可以使用 PHPUnit 进行测试。只需在本地 bloomd 服务器(端口 8673)运行的情况下,从项目根目录运行 phpunit test

示例

php-bloomd 实现了 bloomd 所接受的所有命令。以下是一个基本的示例脚本。

<?php
// php-bloomd - Example basic usage script
require_once __DIR__ . "/vendor/autoload.php";

// Establish a connection to a local bloomd with client
$bloomd = new PhpBloomd\BloomdClient("localhost", 8673);

// Create a filter
if (!$bloomd->createFilter("php"))
{
	printf("example: failed to create filter\n");
	exit;
}

// Create a filter object to use more concise, object-oriented interface
$filter = $bloomd->filter("php");

// Set a couple of values in filter, using both BloomdClient and direct BloomFilter
// Either method may be used for all functions which accept a filter name as first parameter
$bloomd->set("php", "foo");
$filter->set("bar");

// Check the filter for membership
if ($bloomd->check("php", "foo"))
{
	printf("example: got it!\n");
}

// Bulk set values
$results = $filter->bulk(array("foo", "bar", "baz"));
foreach ($results as $k => $v)
{
	printf("%s -> %s\n", $k, $v ? "true" : "false");
}

// Multi check values
$results = $filter->multi(array("foo", "bar", "baz"));
foreach ($results as $k => $v)
{
	printf("%s -> %s\n", $k, $v ? "true" : "false");
}

// Check for any value in array
if ($filter->any(array("foo", "qux")))
{
	printf("any: yes!\n");
}

// Check for all values in array
if ($filter->all(array("foo", "bar", "baz")))
{
	printf("all: yes!\n");
}

// Drop filter
$filter->dropFilter();