PHP code example of iperamuna / laravel-redis-bloom
1. Go to this page and download the library: Download iperamuna/laravel-redis-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/ */
iperamuna / laravel-redis-bloom example snippets
return [
'error_rate' => 0.001, // 0.1% false positive rate
'capacity' => 1000000, // Initial capacity of 1 million items
'redis_connection' => 'default', // Redis connection name from database.php
'filters' => [
'emails' => 'bf:users:emails',
'ips' => 'bf:security:blocked_ips',
'phones' => 'bf:customers:phones',
],
'rotation_keep_versions' => 3, // Keep last 3 rotated versions for safety
];
use Iperamuna\LaravelRedisBloom\Facades\Bloom;
// Single entry ingestion
Bloom::filter('emails')->add('[email protected]');
// High-speed membership check
if (Bloom::filter('emails')->exists('[email protected]')) {
// This value probably exists (Probabilistic result)
}
// Bulk ingestion (Pipelined for performance)
Bloom::filter('ips')->addMany([
'127.0.0.1',
'192.168.1.1',
'10.0.0.1'
]);
// Check Bloom first, then verify against the database only if Bloom says "maybe"
$exists = Bloom::filter('emails')->check($email, function ($email) {
return \App\Models\User::where('email', $email)->exists();
});
use Iperamuna\LaravelRedisBloom\Rules\BloomRule;
$request->validate([
// Standard mode: Fails if Bloom says "maybe exists"
'email' => ['e)],
// String syntax support
'ip' => '