kevago

package module
v0.0.0-...-4c825eb Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

README

KEVAGO - A dead simple Go client for Keva

Pooled client

Default options
client,_ := NewDefaultClient()
ret, _ = cl.Set("key1", "value1")
fmt.Println(ret)
ret, _ := cl.Get("key1")
fmt.Println(ret)
More options

Create a client to Keva server, which under the hood holds a connection pool. Each time a command is called, client gets a connecton from pool and use it.

poolOpts := pool.Options{
    PoolTimeout: time.Second, // max time to wait to get new connection from pool
    PoolSize:    20, // max number of connection can get from the pool
    MinIdleConn: 5,
    Address:     "localhost:6767",
    Dialer: func(ctx context.Context,addr string) (net.Conn, error) { //Must define dialer func
        conn, err := net.Dial("tcp", addr)
        if err != nil {
            return nil, err
        }
        return conn, err
    },
    IdleTimeout:        time.Minute * 5, // if connection lives longer than 5 minutes, it is removable
    MaxConnAge:         time.Minute * 10, // all connections cannot live longer than this
    IdleCheckFrequency: time.Minute * 5, // reap staled connections after 5 minutes
}
client, _ := NewClient(Config{
    Pool: poolOpts,
})
ret, _ = cl.Set("key1", "value1")
fmt.Println(ret)
ret, _ := cl.Get("key1")
fmt.Println(ret)

Ring Client

Connect to multiple Keva nodes and load balance request by consistent hashing the first key of a command. If one of the node goes down, the ring ignore that instance and rebalance using the remaining nodes, but it won't guarantee consistency. This means the datas allocated to the previous set of nodes are no longer belong to the same instance.

client,_ := NewDefaultRing([]string{"localhost:6767","localhost:6768"})
ret, _ = cl.Set("key1", "value1")
fmt.Println(ret)
ret, _ := cl.Get("key1")
fmt.Println(ret)

Credit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAddress = "localhost:6767"
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(c ClientOptions) (*Client, error)

func NewDefaultClient

func NewDefaultClient() (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (Client) Delete

func (c Client) Delete(key string) (string, error)

func (Client) Expire

func (c Client) Expire(key string, d time.Duration) (string, error)

func (Client) Get

func (c Client) Get(key string) (string, error)

TODO: remove boiler plating code, reuse code according to input/output type

func (Client) Info

func (c Client) Info() (string, error)

func (Client) Ping

func (c Client) Ping() error

func (Client) Set

func (c Client) Set(key string, value string) (string, error)

type ClientOptions

type ClientOptions struct {
	Pool pool.Options
}

type Cmd

type Cmd interface {
	Name() string
	Args() []string
	ReadResult(r *proto.Reader) error
}

type CmdHandlers

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

type ConsistentHash

type ConsistentHash interface {
	Lookup(key string) string
}

type HashAlgo

type HashAlgo string
var (
	Rendezvous HashAlgo = "rendezvous"
	Jump       HashAlgo = "jump"
	Maglev     HashAlgo = "maglev"
)

type RendezvousHasher

type RendezvousHasher struct {
	*rendezvous.Rendezvous
}

func (RendezvousHasher) Get

func (s RendezvousHasher) Get(input string) string

type Ring

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

func NewDefaultRing

func NewDefaultRing(addr []string) (*Ring, error)

func NewRing

func NewRing(opts RingOptions) (*Ring, error)

NewRing return a Ring behaves like a single client, with consistent hashing

func (*Ring) Close

func (r *Ring) Close() error

func (Ring) Delete

func (c Ring) Delete(key string) (string, error)

func (Ring) Expire

func (c Ring) Expire(key string, d time.Duration) (string, error)

func (Ring) Get

func (c Ring) Get(key string) (string, error)

TODO: remove boiler plating code, reuse code according to input/output type

func (Ring) Info

func (c Ring) Info() (string, error)

func (Ring) Ping

func (c Ring) Ping() error

func (Ring) Set

func (c Ring) Set(key string, value string) (string, error)

type RingClientOpt

type RingClientOpt struct {
	PoolTimeout        time.Duration
	PoolSize           int
	MinIdleConn        int
	Dialer             func(ctx context.Context, addr string) (net.Conn, error)
	IdleTimeout        time.Duration
	MaxConnAge         time.Duration
	IdleCheckFrequency time.Duration
}

type RingOptions

type RingOptions struct {
	HealthCheckFrequency time.Duration
	Addresses            []string
	HashAlgorithm        HashAlgo

	ClientOptions RingClientOpt
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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