etcd

package
v3.0.11+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

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
}

Client is a wrapped etcd client that support some simple method

func NewClient

func NewClient(cli *clientv3.Client, root string) *Client

NewClient returns a wrapped etcd client

func NewClientFromCfg

func NewClientFromCfg(endpoints []string, dialTimeout time.Duration, root string, security *tls.Config) (*Client, error)

NewClientFromCfg returns a wrapped etcd client

func (*Client) Close

func (e *Client) Close() error

Close shutdowns the connection to etcd

func (*Client) Create

func (e *Client) Create(ctx context.Context, key string, val string, opts []clientv3.OpOption) (int64, error)

Create guarantees to set a key = value with some options(like ttl)

func (*Client) Delete

func (e *Client) Delete(ctx context.Context, key string, withPrefix bool) error

Delete deletes the key/values with matching prefix or key

func (*Client) DoTxn

func (e *Client) DoTxn(ctx context.Context, operations []*Operation) (int64, error)

DoTxn does some operation in one transaction. Note: should only have one opereration for one key, otherwise will get duplicate key error.

func (*Client) Get

func (e *Client) Get(ctx context.Context, key string) (value []byte, revision int64, err error)

Get returns a key/value matchs the given key

func (*Client) GetClient

func (e *Client) GetClient() *clientv3.Client

GetClient returns client

func (*Client) List

func (e *Client) List(ctx context.Context, key string) (node *Node, revision int64, err error)

List returns the trie struct that constructed by the key/value with same prefix

func (*Client) Update

func (e *Client) Update(ctx context.Context, key string, val string, ttl int64) error

Update updates a key/value. set ttl 0 to disable the Lease ttl feature

func (*Client) UpdateOrCreate

func (e *Client) UpdateOrCreate(ctx context.Context, key string, val string, ttl int64) error

UpdateOrCreate updates a key/value, if the key does not exist then create, or update

func (*Client) Watch

func (e *Client) Watch(ctx context.Context, prefix string, revision int64) clientv3.WatchChan

Watch watchs the events of key with prefix.

type Node

type Node struct {
	Value  []byte
	Childs map[string]*Node
}

Node organizes the ectd query result as a Trie tree

type OpType

type OpType string

OpType is operation's type in etcd

var (
	// CreateOp is create operation type
	CreateOp OpType = "create"

	// UpdateOp is update operation type
	UpdateOp OpType = "update"

	// DeleteOp is delete operation type
	DeleteOp OpType = "delete"
)

type Operation

type Operation struct {
	Tp         OpType
	Key        string
	Value      string
	TTL        int64
	WithPrefix bool

	Opts []clientv3.OpOption
}

Operation represents an operation in etcd, include create, update and delete.

func (*Operation) String

func (o *Operation) String() string

String implements Stringer interface.

Jump to

Keyboard shortcuts

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