redis_bloom_go

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

README

license CircleCI GitHub issues Codecov GoDoc

redisbloom-go

Go client for RedisBloom (https://github.com/RedisBloom/redisbloom), based on redigo.

Installing

$ go get github.com/RedisBloom/redisbloom-go

Running tests

A simple test suite is provided, and can be run with:

$ go test

The tests expect a Redis server with the RedisBloom module loaded to be available at localhost:6379. You can easily launch RedisBloom with Docker in the following manner:

docker run -d -p 6379:6379 --name redis-redisbloom redislabs/rebloom:latest 

Example Code

package main 

import (
        "fmt"
        redisbloom "github.com/RedisBloom/redisbloom-go"
)

func main() {
		// Connect to localhost with no password
    var client = redisbloom.NewClient("localhost:6379", "nohelp", nil)
       
    // BF.ADD mytest item 
    _, err := client.Add("mytest", "myItem")
    if err != nil {
        fmt.Println("Error:", err)
    }
    
    exists, err := client.Exists("mytest", "myItem")
    if err != nil {
        fmt.Println("Error:", err)
    }
    fmt.Println("myItem exists in mytest: ", exists)
}

Supported RedisBloom Commands

Bloom Filter
Command Recommended API and godoc
BF.RESERVE Reserve
BF.ADD Add
BF.MADD BfAddMulti
BF.INSERT BfInsert
BF.EXISTS Exists
BF.MEXISTS BfExistsMulti
BF.SCANDUMP BfScanDump
BF.LOADCHUNK BfLoadChunk
BF.INFO Info
Cuckoo Filter
Command Recommended API and godoc
CF.RESERVE CfReserve
CF.ADD CfAdd
CF.ADDNX CfAddNx
CF.INSERT CfInsert
CF.INSERTNX CfInsertNx
CF.EXISTS CfExists
CF.DEL CfDel
CF.COUNT CfCount
CF.SCANDUMP CfScanDump
CF.LOADCHUNK CfLoadChunk
CF.INFO CfInfo
Count-Min Sketch
Command Recommended API and godoc
CMS.INITBYDIM CmsInitByDim
CMS.INITBYPROB CmsInitByProb
CMS.INCRBY CmsIncrBy
CMS.QUERY CmsQuery
CMS.MERGE CmsMerge
CMS.INFO CmsInfo
TopK Filter
Command Recommended API and godoc
TOPK.RESERVE TopkReserve
TOPK.ADD TopkAdd
TOPK.INCRBY TopkIncrby
TOPK.QUERY TopkQuery
TOPK.COUNT TopkCount
TOPK.LIST TopkList
TOPK.INFO TopkInfo

License

redisbloom-go is distributed under the BSD 3-Clause license - see LICENSE

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInsertArgs added in v0.5.0

func GetInsertArgs(key string, cap int64, noCreate bool, items []string) redis.Args

func ParseInfoReply added in v0.5.0

func ParseInfoReply(values []interface{}, err error) (map[string]int64, error)

Types

type Client

type Client struct {
	Pool ConnPool
	Name string
}

Client is an interface to time series redis commands

func NewClient

func NewClient(addr, name string, authPass *string) *Client

NewClient creates a new client connecting to the redis host, and using the given name as key prefix. Addr can be a single host:port pair, or a comma separated list of host:port,host:port... In the case of multiple hosts we create a multi-pool and select connections at random

Example

exemplifies the NewClient function

package main

import (
	"fmt"
	redisbloom "github.com/RedisBloom/redisbloom-go"
)

func main() {
	host := "localhost:6379"
	var client = redisbloom.NewClient(host, "nohelp", nil)

	// BF.ADD mytest item
	_, err := client.Add("mytest", "myItem")
	if err != nil {
		fmt.Println("Error:", err)
	}

	exists, err := client.Exists("mytest", "myItem")
	if err != nil {
		fmt.Println("Error:", err)
	}
	fmt.Println("myItem exists in mytest: ", exists)
}
Output:

myItem exists in mytest:  true

func NewClientFromPool added in v0.3.0

func NewClientFromPool(pool *redis.Pool, name string) *Client

NewClientFromPool creates a new Client with the given pool and client name

Example

exemplifies the NewClientFromPool function

package main

import (
	"fmt"
	redisbloom "github.com/RedisBloom/redisbloom-go"
	"github.com/gomodule/redigo/redis"
	"log"
)

func main() {
	host := "localhost:6379"
	password := ""
	pool := &redis.Pool{Dial: func() (redis.Conn, error) {
		return redis.Dial("tcp", host, redis.DialPassword(password))
	}}
	client := redisbloom.NewClientFromPool(pool, "bloom-client-1")

	// BF.ADD mytest item
	_, err := client.Add("mytest", "myItem")
	if err != nil {
		log.Fatalf("Error: %v", err)
	}

	exists, err := client.Exists("mytest", "myItem")
	if err != nil {
		log.Fatalf("Error: %v", err)
	}
	fmt.Println("myItem exists in mytest: ", exists)
}
Output:

myItem exists in mytest:  true

func (*Client) Add

func (client *Client) Add(key string, item string) (exists bool, err error)

Add - Add (or create and add) a new value to the filter args: key - the name of the filter item - the item to add

func (*Client) BfAddMulti added in v0.3.0

func (client *Client) BfAddMulti(key string, items []string) ([]int64, error)

BfAddMulti - Adds one or more items to the Bloom Filter, creating the filter if it does not yet exist. args: key - the name of the filter item - One or more items to add

func (*Client) BfExistsMulti added in v0.3.0

func (client *Client) BfExistsMulti(key string, items []string) ([]int64, error)

BfExistsMulti - Determines if one or more items may exist in the filter or not. args: key - the name of the filter item - one or more items to check

func (*Client) BfInsert added in v0.9.0

func (client *Client) BfInsert(key string, cap int64, errorRatio float64, expansion int64, noCreate bool, nonScaling bool, items []string) (res []int64, err error)

This command will add one or more items to the bloom filter, by default creating it if it does not yet exist.

func (*Client) BfLoadChunk added in v0.9.0

func (client *Client) BfLoadChunk(key string, iter int64, data []byte) (string, error)

Restores a filter previously saved using SCANDUMP .

func (*Client) BfScanDump added in v0.9.0

func (client *Client) BfScanDump(key string, iter int64) (int64, []byte, error)

Begins an incremental save of the bloom filter.

func (*Client) CfAdd added in v0.5.0

func (client *Client) CfAdd(key string, item string) (bool, error)

Adds an item to the cuckoo filter, creating the filter if it does not exist.

func (*Client) CfAddNx added in v0.5.0

func (client *Client) CfAddNx(key string, item string) (bool, error)

Adds an item to a cuckoo filter if the item did not exist previously.

func (*Client) CfCount added in v0.5.0

func (client *Client) CfCount(key string, item string) (int64, error)

Returns the number of times an item may be in the filter.

func (*Client) CfDel added in v0.5.0

func (client *Client) CfDel(key string, item string) (bool, error)

Deletes an item once from the filter.

func (*Client) CfExists added in v0.5.0

func (client *Client) CfExists(key string, item string) (bool, error)

Check if an item exists in a Cuckoo Filter

func (*Client) CfInfo added in v0.5.0

func (client *Client) CfInfo(key string) (map[string]int64, error)

Return information about key

func (*Client) CfInsert added in v0.5.0

func (client *Client) CfInsert(key string, cap int64, noCreate bool, items []string) ([]int64, error)

Adds one or more items to a cuckoo filter, allowing the filter to be created with a custom capacity if it does not yet exist.

func (*Client) CfInsertNx added in v0.5.0

func (client *Client) CfInsertNx(key string, cap int64, noCreate bool, items []string) ([]int64, error)

Adds one or more items to a cuckoo filter, allowing the filter to be created with a custom capacity if it does not yet exist.

func (*Client) CfLoadChunk added in v0.5.0

func (client *Client) CfLoadChunk(key string, iter int64, data []byte) (string, error)

Restores a filter previously saved using SCANDUMP

func (*Client) CfReserve added in v0.5.0

func (client *Client) CfReserve(key string, capacity int64, bucketSize int64, maxIterations int64, expansion int64) (string, error)

Create an empty cuckoo filter with an initial capacity of {capacity} items.

func (*Client) CfScanDump added in v0.5.0

func (client *Client) CfScanDump(key string, iter int64) (int64, []byte, error)

Begins an incremental save of the cuckoo filter.

func (*Client) CmsIncrBy added in v0.5.0

func (client *Client) CmsIncrBy(key string, itemIncrements map[string]int64) ([]int64, error)

Increases the count of item by increment. Multiple items can be increased with one call.

func (*Client) CmsInfo added in v0.5.0

func (client *Client) CmsInfo(key string) (map[string]int64, error)

Returns width, depth and total count of the sketch.

func (*Client) CmsInitByDim added in v0.5.0

func (client *Client) CmsInitByDim(key string, width int64, depth int64) (string, error)

Initializes a Count-Min Sketch to dimensions specified by user.

func (*Client) CmsInitByProb added in v0.5.0

func (client *Client) CmsInitByProb(key string, error float64, probability float64) (string, error)

Initializes a Count-Min Sketch to accommodate requested capacity.

func (*Client) CmsMerge added in v0.5.0

func (client *Client) CmsMerge(dest string, srcs []string, weights []int64) (string, error)

Merges several sketches into one sketch, stored at dest key All sketches must have identical width and depth.

func (*Client) CmsQuery added in v0.5.0

func (client *Client) CmsQuery(key string, items []string) ([]int64, error)

Returns count for item.

func (*Client) Exists

func (client *Client) Exists(key string, item string) (exists bool, err error)

Exists - Determines whether an item may exist in the Bloom Filter or not. args: key - the name of the filter item - the item to check for

func (*Client) Info added in v0.2.0

func (client *Client) Info(key string) (info map[string]int64, err error)

Info - Return information about key args: key - the name of the filter

func (*Client) Reserve added in v0.2.0

func (client *Client) Reserve(key string, error_rate float64, capacity uint64) (err error)

Reserve - Creates an empty Bloom Filter with a given desired error ratio and initial capacity. args: key - the name of the filter error_rate - the desired probability for false positives capacity - the number of entries you intend to add to the filter

func (*Client) TopkAdd added in v0.3.0

func (client *Client) TopkAdd(key string, items []string) ([]string, error)

Adds an item to the data structure.

func (*Client) TopkCount added in v0.3.0

func (client *Client) TopkCount(key string, items []string) (result []int64, err error)

Returns count for an item.

func (*Client) TopkIncrBy added in v0.3.0

func (client *Client) TopkIncrBy(key string, itemIncrements map[string]int64) ([]string, error)

Increase the score of an item in the data structure by increment.

func (*Client) TopkInfo added in v0.3.0

func (client *Client) TopkInfo(key string) (map[string]string, error)

Returns number of required items (k), width, depth and decay values.

func (*Client) TopkList added in v0.3.0

func (client *Client) TopkList(key string) ([]string, error)

Return full list of items in Top K list.

func (*Client) TopkQuery added in v0.3.0

func (client *Client) TopkQuery(key string, items []string) ([]int64, error)

Checks whether an item is one of Top-K items.

func (*Client) TopkReserve added in v0.3.0

func (client *Client) TopkReserve(key string, topk int64, width int64, depth int64, decay float64) (string, error)

Initializes a TopK with specified parameters.

type ConnPool

type ConnPool interface {
	Get() redis.Conn
	Close() error
}

type MultiHostPool

type MultiHostPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMultiHostPool

func NewMultiHostPool(hosts []string, authPass *string) *MultiHostPool

func (*MultiHostPool) Close added in v0.3.0

func (p *MultiHostPool) Close() (err error)

func (*MultiHostPool) Get

func (p *MultiHostPool) Get() redis.Conn

type SingleHostPool

type SingleHostPool struct {
	*redis.Pool
}

func NewSingleHostPool

func NewSingleHostPool(host string, authPass *string) *SingleHostPool

Jump to

Keyboard shortcuts

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