bloomd

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

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

Go to latest
Published: May 18, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package bloomd provides a client abstraction around the BloomD interface.

Example:

client := bloomd.NewClient("10.0.0.30:8673")
filter := bloomd.Filter{Name: "coolfilter"}
if err := bloomd.CreateFilter(filter); err != nil {
	// handle error
}
filters, _ := bloomd.ListFilters()
fmt.Printf("%+v", filters["coolfilter"])

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomdError

type BloomdError struct {
	ErrorString string
}

BloomdError struct

func (*BloomdError) Error

func (err *BloomdError) Error() string

Error returns the internal error representation

type Client

type Client struct {
	Server     string
	Timeout    int
	Conn       *Connection
	ServerInfo string
	InfoTime   int
	HashKeys   bool
}

Client struct is the main entry point to interact with a bloomd server. If using multiple BloomD servers, it is recommended to use a BloomD Ring and only use the proxy as the Server field for your client.

func NewClient

func NewClient(address string) Client

NewClient instanciates a new connection to bloomd

func (*Client) Close

func (c *Client) Close()

Close closes the underlying tcp connection.

func (*Client) CreateFilter

func (c *Client) CreateFilter(f *Filter) error

CreateFilter creates a new filter with provided parameters

func (*Client) Flush

func (c *Client) Flush() error

Flush instructs server to flush to disk

func (*Client) GetFilter

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

GetFilter instanciates and returns a filter to further Set and Check keys.

func (*Client) ListFilters

func (c *Client) ListFilters() (responses map[string]string, err error)

ListFilters lists all the available filters

type Connection

type Connection struct {
	Server   string
	Timeout  time.Duration
	Socket   *net.TCPConn
	File     *os.File
	Attempts int
	Reader   *bufio.Reader
}

Connection materializes a concrete connection to bloomd

func (*Connection) Read

func (c *Connection) Read() (line string, err error)

Read returns a single line from the socket file

func (*Connection) ReadBlock

func (c *Connection) ReadBlock() (lines []string, err error)

ReadBlock reads a response block from the server. The servers responses are between `start` and `end` which can be optionally provided. Returns an array of the lines within the block.

func (*Connection) Send

func (c *Connection) Send(cmd string) error

Send sends a command to the server

func (*Connection) SendAndReceive

func (c *Connection) SendAndReceive(cmd string) (string, error)

SendAndReceive is a convenience wrapper around `send` and `read`. Sends a command, and reads the response, performing a retry if necessary.

type Filter

type Filter struct {
	Name     string
	Conn     *Connection
	HashKeys bool
	// Optional
	Capacity int     // The initial capacity of the filter
	Prob     float64 // The inital probability of false positives
	InMemory bool    // If True, specified that the filter should be created
}

Filter represents a bloom filter

func (*Filter) Bulk

func (f *Filter) Bulk(keys []string) (responses []bool, err error)

Performs a bulk set command, adds multiple keys in the filter

func (*Filter) Check

func (f *Filter) Check(key string) (bool, error)

Check checks if the key exists in the filter. Returns True/False

func (*Filter) Clear

func (f *Filter) Clear() error

Clear clears the filter on the server

func (*Filter) Close

func (f *Filter) Close() error

Close closes the filter on the server

func (*Filter) Drop

func (f *Filter) Drop() error

Drop deletes the filter permanently from the server

func (*Filter) Flush

func (f *Filter) Flush() error

Flush forces the filter to flush to disk

func (*Filter) Info

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

Info returns the info dictionary about the filter

func (*Filter) Multi

func (f *Filter) Multi(keys []string) (responses []bool, err error)

Performs a multi command, checks for multiple keys in the filter

func (*Filter) Set

func (f *Filter) Set(key string) (bool, error)

Set adds a new key to the filter. Returns True/False if the key was added

Jump to

Keyboard shortcuts

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