hb

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 5 Imported by: 0

README

Honey Badger Go client

Honey Badger is simple and fast key/value database server build on top of BadgerDB. It uses gRPC as transport protocol.

Getting Started

Installation
go get github.com/honey-badger-io/go-client
Usage
package main

import (
	"context"
	"fmt"

	hb "github.com/honey-badger-io/go-client"
)

func main() {
	client, err := hb.NewClient("127.0.0.1:18950")
	if err != nil {
		panic(err)
	}

	errSet := client.Data(context.Background(), "database").Set("some-key", []byte("some data"))
	if errSet != nil {
		panic(errSet)
	}

	data, hit, errGet := client.Data(context.Background(), "database").Get("some-key")
	if errGet != nil {
		panic(errGet)
	}

	fmt.Printf("Data: %v\n", string(data))
	fmt.Printf("Hit: %v\n", hit)
}
Run demo

First you must run server. Either run it from source code or run as docker container:

docker run --name honey-badger -p 18950:18950 -d meeron/honey-badger:latest

Then run demo program:

$ go run .
Data: some data
Hit: true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(target string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Data

func (c *Client) Data(ctx context.Context, db string) *Data

func (*Client) Db added in v0.3.0

func (c *Client) Db(ctx context.Context, db string) *DbClient

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) (string, error)

type CreateDbOptions added in v0.3.0

type CreateDbOptions struct {
	InMemory bool
}

type Data

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

func (*Data) Delete

func (d *Data) Delete(key string) error

func (*Data) DeleteByPrefix

func (d *Data) DeleteByPrefix(prefix string) error

func (*Data) Get

func (d *Data) Get(key string) ([]byte, bool, error)

func (*Data) NewSendStream

func (d *Data) NewSendStream() (*SendStream, error)

func (*Data) Read

func (d *Data) Read(prefix string, callback ReadCallback) error

func (*Data) Set

func (d *Data) Set(key string, data []byte) error

func (*Data) SetWithTtl

func (d *Data) SetWithTtl(key string, data []byte, ttl int32) error

type DbClient added in v0.3.0

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

func (*DbClient) Create added in v0.3.0

func (d *DbClient) Create(opt CreateDbOptions) error

func (*DbClient) Drop added in v0.3.0

func (d *DbClient) Drop() error

func (*DbClient) EnsureDb added in v0.3.0

func (d *DbClient) EnsureDb(opt CreateDbOptions) error

func (*DbClient) Exists added in v0.3.0

func (d *DbClient) Exists() (bool, error)

type ReadCallback

type ReadCallback func(key string, data []byte) error

type SendStream

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

func (*SendStream) Close

func (s *SendStream) Close() error

func (*SendStream) Send

func (s *SendStream) Send(key string, data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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