1. Go to this page and download the library: Download averias/phpredis-bloom library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
averias / phpredis-bloom example snippets
use Averias\RedisBloom\Factory\RedisBloomFactory;
// instantiate a RedisBloomClient from RedisBloomFactory with default connection options
$factory = new RedisBloomFactory();
$client = $factory->createClient();
// then you can execute whatever redis bloom command for each of the 4 data types
$result = $client->bloomFilterAdd('filter-key', 'item-15');
// example for BloomFilter data types class
use Averias\RedisBloom\Factory\RedisBloomFactory;
// instantiate a BloomFilter class from RedisBloomFactory with default connection options
$factory = new RedisBloomFactory();
$bloomFilter = $factory->createBloomFilter('filter-key');
// then you can execute whatever Bloom Filter command on 'filter-key' filter
// adding one item to Bloom Filter 'filter-key'
$result = $bloomFilter->add('item1'); // returns true
// adding 2 items more to Bloom Filter 'filter-key'
$result = $bloomFilter->multiAdd('item2', 15); // returns and array [true, true]
// checking if item 'item1' exists in 'filter-key' Bloom Filter
$result = $bloomFilter->exists('item1'); // returns true
// adding one item more
$result = $bloomFilter->add(17.2); // returns true
// checking if a list items exist in 'filter-key' Bloom Filter
$result = $bloomFilter->multiExists('item1', 15, 'foo'); // returns and array [true, true, false] since 'foo' doesn't exists
use Averias\RedisBloom\Enum\Connection;
use Averias\RedisBloom\Factory\RedisBloomFactory;
> '127.0.0.1',
* 'port' => 6379,
* 'timeout' => 0.0, // seconds
* 'retryInterval' => 15 // milliseconds
* 'readTimeout' => 2, // seconds
* 'persistenceId' => null // string for persistent connections, null for no persistent ones
* 'database' => 0 // Redis database index [0..15]
* ]
*
* you can create a factory with default connection by not passing any param in the constructor
* $defaultFactory = new RedisBloomFactory();
*/
// create a factory with default connection but pointing to database 15
$factoryDB15 = new RedisBloomFactory([Connection::DATABASE => 15]);
// it creates a RedisBloomClient with same default connection configuration as specified in factory above
$clientDB15 = $factoryDB15->createClient();
// using the same factory you can create a BloomFilter object pointing
// to database 14 and filter name = 'example-filter'
$bloomFilterDB14 = $factoryDB15->createBloomFilter(EXAMPLE_FILTER, [Connection::DATABASE => 14]);
// add 'item-15' to 'example-filter' bloom filter on database 15
$clientDB15->bloomFilterAdd(EXAMPLE_FILTER, 'item-15');
// add 'item-14' to 'example-filter' bloom filter on database 14
$bloomFilterDB14->add('item-14');
// disconnect
$bloomFilterDB14->disconnect();
// create another RedisBloomClient pointing to database 14
$clientDB14 = $factoryDB15->createClient([Connection::DATABASE => 14]);
$result = $clientDB15->bloomFilterExists(EXAMPLE_FILTER, 'database15'); //true
$result = $clientDB15->bloomFilterExists(EXAMPLE_FILTER, 'database14'); // false
$result = $clientDB14->bloomFilterExists(EXAMPLE_FILTER, 'database15'); // false
$result = $clientDB14->bloomFilterExists(EXAMPLE_FILTER, 'database14'); // true
// delete bloom filter on database 15
$clientDB15->executeRawCommand('DEL', EXAMPLE_FILTER);
// delete bloom filter on database 14
$clientDB14->del(EXAMPLE_FILTER);
// disconnect
$clientDB15->disconnect();
$clientDB14->disconnect();
// automatic reconnection
$bloomFilterDB14->add('reconnected');
$exist = $bloomFilterDB14->exists('reconnected'); //true
$bloomFilterDB14->disconnect();
use Averias\RedisBloom\Enum\BloomCommands;
// raw Redis Bloom command
$client->executeRawCommand(BloomCommands::BF_ADD, 'filter-name', 'value');
// raw Redis command
$client->executeRawCommand('hget', 'hash-key', 'foo');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.