bloomd

package module
v0.0.0-...-be6f5f5 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2018 License: MIT Imports: 13 Imported by: 4

README

Build Status Coverage Status GoDoc

go-bloomd

Bloomd (https://github.com/armon/bloomd) client (with connection pool) for Go

$ go get -u github.com/Applifier/go-bloomd

Example

c, _ := bloomd.NewFromAddr("localhost:8673")
defer c.Close()

f, _ := c.CreateFilter(Filter{
	Name: "somefilter",
})

f.Set("foobar")
found, _ := f.Check("foobar")

Client pool

Client pools can be used to maintain a pool of persistent connections to bloomd server

p, _ := bloomd.NewPoolFromAddr(5, 10, "localhost:8673")
c, _ := p.Get()
defer c.Close() // Return client back to pool

f, _ := c.CreateFilter(Filter{
	Name: "somefilter",
})

f.Set("foobar")
found, _ := f.Check("foobar")

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBufferSize = 4096

DefaultBufferSize is the default size for the read buffer

View Source
var ErrCursorOverLength = errors.New("resultReader: cursor is over length")

Functions

func Connect

func Connect(u *url.URL) (net.Conn, error)

Connect initialises a new connection to bloomd server it uses url.Scheme to determine which type of connection should be established: unix - for Unix Domain Socket tcp - for TCP

func PutArrayReader

func PutArrayReader(reader *ArrayReader)

Types

type ArrayReader

type ArrayReader struct {
	// contains filtered or unexported fields
}

func GetArrayReader

func GetArrayReader(arr []Key) *ArrayReader

func NewArrayReader

func NewArrayReader(arr ...Key) *ArrayReader

func (ArrayReader) Current

func (sr ArrayReader) Current() Key

func (*ArrayReader) Next

func (sr *ArrayReader) Next() bool

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a bloomd client

func NewFromAddr

func NewFromAddr(addr string) (*Client, error)

NewFromAddr creates a new bloomd client from addr

func NewFromConn

func NewFromConn(conn net.Conn) (cli *Client, err error)

NewFromConn creates a new bloomd client from net.Conn

func NewFromURL

func NewFromURL(u *url.URL) (*Client, error)

NewFromURL creates a new bloomd client from URL struct

func (*Client) Close

func (cli *Client) Close() error

Close closes underlying connection or return the connection to the Pool if one was used

func (*Client) CreateFilter

func (cli *Client) CreateFilter(name string, capacity int, prob float64, inMemory bool) (Filter, error)

CreateFilter creates a new filter or returns an existing one

func (*Client) GetFilter

func (cli *Client) GetFilter(name string) Filter

GetFilter returns a previously created filter

func (*Client) ListFilters

func (cli *Client) ListFilters() ([]Filter, error)

ListFilters list all filters

func (*Client) Ping

func (cli *Client) Ping() error

Ping pings the server

type Error

type Error struct {
	Message                  string
	Err                      error
	ShouldRetryWithNewClient bool
}

Error custom error for bloomd related actions

func (Error) Error

func (e Error) Error() string

type Factory

type Factory func() (net.Conn, error)

Factory a factory for conn for the Bloomd client

type Filter

type Filter struct {
	Name string
	// contains filtered or unexported fields
}

Filter represents a single filter in the bloomd server

func (Filter) BulkSet

func (f Filter) BulkSet(reader KeyReader) (ResultReader, error)

BulkSet adds multiple keys to the filter

func (Filter) Check

func (f Filter) Check(key Key) (bool, error)

Check gets a single key to the bloom

func (Filter) Clear

func (f Filter) Clear() error

Clear clears the filter

func (Filter) Close

func (f Filter) Close() error

Close closes the filter on the server

func (Filter) Drop

func (f Filter) Drop() error

Drop drops the filter on the server

func (Filter) Flush

func (f Filter) Flush() error

Flush force flushes the filter

func (Filter) Info

func (f Filter) Info() (map[string]string, error)

Info returns info map from the server

func (Filter) MultiCheck

func (f Filter) MultiCheck(reader KeyReader) (ResultReader, error)

MultiCheck checks multiple keys for the filter

func (Filter) Set

func (f Filter) Set(key Key) (bool, error)

Set sets a single key to the bloom

type Key

type Key []byte

Key is bloom filter key

type KeyReader

type KeyReader interface {
	Next() bool
	Current() Key
}

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool of bloomd clients

func NewPoolFromAddr

func NewPoolFromAddr(initialCap, maxCap int, addr string) (*Pool, error)

NewPoolFromAddr return a new pool of client for addr

func NewPoolFromFactory

func NewPoolFromFactory(initialCap, maxCap int, factory Factory) (*Pool, error)

NewPoolFromFactory returns a new pool of clients for a connection factory

func NewPoolFromURL

func NewPoolFromURL(initialCap, maxCap int, u *url.URL) (*Pool, error)

NewPoolFromURL return a new pool of client for locator

func (*Pool) Close

func (p *Pool) Close()

Close closes pool

func (*Pool) Get

func (p *Pool) Get() (*Client, error)

Get returns a new client from the pool. Client is returned to pool by calling client.Close()

func (*Pool) Len

func (p *Pool) Len() int

Len returns pool length

type ResultReader

type ResultReader interface {
	Next() (bool, error)
	Read(p []bool) (n int, err error)
	Length() int // Usually any Reader implementation should not contain Length() method but from bloomd protocol we always know the result length - so it could be usefull information
	Close() error
}

ResultReader allows to read filter results

Directories

Path Synopsis
extensions
utils

Jump to

Keyboard shortcuts

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