bloomfilter

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 5 Imported by: 0

README

go-bloomfilter

A simple and high-performance Bloom filter written in golang.

Support memory storage and redis.

Examples

MemoryBloomFilter
import bloomfilter "github.com/alovn/go-bloomfilter"

bloom := bloomfilter.NewMemoryBloomFilter(10000)
_ = bloom.Put([]byte("bloom"))
exists,err := bloom.MightContain(bs)

RedisBloomFilter
import (
    bloomfilter "github.com/alovn/go-bloomfilter"
    "github.com/redis/go-redis/v9"
)

rdb := redis.NewClient(&redis.Options{
    Addr:     "127.0.0.1:6379",
    Password: "",
    DB:       0,
})
defer rdb.Close()

key := "redis bloomfilter"

bloom := bloomfilter.NewRedisBloomFilter(rdb, "test", 1000000)

bs := []byte(key)
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

redis cluster:

rdb := redis.NewClusterClient(&redis.ClusterOptions{
    Addrs: []string{
        "127.0.0.1:6371",
        "127.0.0.1:6372",
        "127.0.0.1:6373",
    },
    Password: "1234",
})
bloom := bloomfilter.NewRedisBloomFilter(rdb, "test", 1000000)

Documentation

Overview

A simple and high-performance Bloom filter written in golang.

import bloomfilter "github.com/alovn/go-bloomfilter"

MemoryBloomFilter:

bloom := bloomfilter.NewMemoryBloomFilter(10000)
bs := []byte("bloom")
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

RedisBloomFilter:

cli := redis.NewClient(&redis.Options{
	Addr:     "127.0.0.1:6379",
	Password: "",
	DB:       0,
})
key := "redis bloomfilter"
bloom := bloomfilter.NewRedisBloomFilter(cli, "test", 1000000)
bs := []byte(key)
_ = bloom.Put(bs)
exists, err := bloom.MightContain(bs)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilter

type BloomFilter interface {
	Put([]byte) error
	MightContain([]byte) (bool, error)
}

BloomFilter interface define

func NewMemoryBloomFilter

func NewMemoryBloomFilter(size uint64) BloomFilter

NewMemoryBloomFilter implementation with memory

func NewRedisBloomFilter added in v1.0.1

func NewRedisBloomFilter(redisCli RedisClient, redisKey string, size uint64) BloomFilter

type RedisClient added in v1.1.0

type RedisClient interface {
	Pipeline() redis.Pipeliner
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL