clientv3

package
v0.0.0-...-aec85aa Latest Latest
Warning

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

Go to latest
Published: May 25, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeDelete = mvccpb.DELETE
	EventTypePut    = mvccpb.PUT
)

Variables

View Source
var (
	CloseDB func()
)

Functions

func GetPrefixRangeEnd

func GetPrefixRangeEnd(prefix string) string

GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.

Types

type Client

type Client struct {
	Cluster
	KV
	Lease
	Watcher
	// contains filtered or unexported fields
}

Client provides and manages an etcd v3 client session.

func New

func New(cfg Config) (*Client, error)

New creates a new etcdv3 client from a given configuration.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client's etcd connections.

func (*Client) Endpoints

func (c *Client) Endpoints() (eps []string)

Endpoints lists the registered endpoints for the client.

type Cluster

type Cluster struct {
}

func (*Cluster) MemberList

func (c *Cluster) MemberList(ctx context.Context) (interface{}, error)

type Cmp

type Cmp pb.Compare

func Compare

func Compare(cmp Cmp, result string, v interface{}) Cmp

func ModRevision

func ModRevision(key string) Cmp

func Version

func Version(key string) Cmp

type CompactOp

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

CompactOp represents a compact operation.

func OpCompact

func OpCompact(rev int64, opts ...CompactOption) CompactOp

OpCompact wraps slice CompactOption to create a CompactOp.

type CompactOption

type CompactOption func(*CompactOp)

CompactOption configures compact operation.

type CompactResponse

type CompactResponse pb.CompactionResponse

type CompareResult

type CompareResult int

type CompareTarget

type CompareTarget int
const (
	CompareVersion CompareTarget = iota
	CompareCreated
	CompareModified
	CompareValue
)

type Config

type Config struct {
	// Endpoints is a list of URLs.
	Endpoints []string `json:"endpoints"`

	// DialKeepAliveTime is the time in seconds after which client pings the server to see if
	// transport is alive.
	DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"`

	// DialKeepAliveTimeout is the time in seconds that the client waits for a response for the
	// keep-alive probe.  If the response is not received in this time, the connection is closed.
	DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`

	// TLS holds the client secure credentials, if any.
	TLS *tls.Config

	DialTimeout time.Duration

	DialOptions []grpc.DialOption
}

type DeleteResponse

type DeleteResponse pb.DeleteRangeResponse

type Event

type Event mvccpb.Event

func (*Event) IsCreate

func (e *Event) IsCreate() bool

IsCreate returns true if the event tells that the key is newly created.

func (*Event) IsModify

func (e *Event) IsModify() bool

IsModify returns true if the event tells that a new value is put on existing key.

type GetResponse

type GetResponse pb.RangeResponse

type KV

type KV interface {
	// Put puts a key-value pair into etcd.
	// Note that key,value can be plain bytes array and string is
	// an immutable representation of that bytes array.
	// To get a string of bytes, do string([]byte{0x10, 0x20}).
	Put(ctx context.Context, key, val string, opts ...OpOption) (*PutResponse, error)

	// Get retrieves keys.
	// By default, Get will return the value for "key", if any.
	// When passed WithRange(end), Get will return the keys in the range [key, end).
	// When passed WithFromKey(), Get returns keys greater than or equal to key.
	// When passed WithRev(rev) with rev > 0, Get retrieves keys at the given revision;
	// if the required revision is compacted, the request will fail with ErrCompacted .
	// When passed WithLimit(limit), the number of returned keys is bounded by limit.
	// When passed WithSort(), the keys will be sorted.
	Get(ctx context.Context, key string, opts ...OpOption) (*GetResponse, error)

	// Delete deletes a key, or optionally using WithRange(end), [key, end).
	Delete(ctx context.Context, key string, opts ...OpOption) (*DeleteResponse, error)

	// Compact compacts etcd KV history before the given rev.
	Compact(ctx context.Context, rev int64, opts ...CompactOption) (*CompactResponse, error)

	// Txn creates a transaction.
	Txn(ctx context.Context) Txn
}

type Lease

type Lease interface {
	// Grant creates a new lease.
	Grant(ctx context.Context, ttl int64) (*LeaseGrantResponse, error)
}

type LeaseGrantResponse

type LeaseGrantResponse struct {
	*pb.ResponseHeader
	ID    LeaseID
	TTL   int64
	Error string
}

LeaseGrantResponse wraps the protobuf message LeaseGrantResponse.

type LeaseID

type LeaseID int64

type LeaseRevokeResponse

type LeaseRevokeResponse pb.LeaseRevokeResponse

type Op

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

Op represents an Operation that kv can execute.

func OpDelete

func OpDelete(key string, opts ...OpOption) Op

func OpGet

func OpGet(key string, opts ...OpOption) Op

func OpPut

func OpPut(key, val string, opts ...OpOption) Op

func (Op) IsCountOnly

func (op Op) IsCountOnly() bool

IsCountOnly returns whether countOnly is set.

func (Op) IsDelete

func (op Op) IsDelete() bool

IsDelete returns true iff the operation is a Delete.

func (Op) IsGet

func (op Op) IsGet() bool

IsGet returns true iff the operation is a Get.

func (Op) IsPut

func (op Op) IsPut() bool

IsPut returns true iff the operation is a Put.

func (Op) IsTxn

func (op Op) IsTxn() bool

func (Op) Rev

func (op Op) Rev() int64

Rev returns the requested revision, if any.

func (Op) Txn

func (op Op) Txn() ([]Cmp, []Op, []Op)

func (Op) ValueBytes

func (op Op) ValueBytes() []byte

ValueBytes returns the byte slice holding the Op's value, if any.

func (*Op) WithValueBytes

func (op *Op) WithValueBytes(v []byte)

WithValueBytes sets the byte slice for the Op's value.

type OpOption

type OpOption func(*Op)

OpOption configures Operations like Get, Put, Delete.

func WithCountOnly

func WithCountOnly() OpOption

WithCountOnly makes the 'Get' request return only the count of keys.

func WithLease

func WithLease(leaseID LeaseID) OpOption

WithLease attaches a lease ID to a key in 'Put' request.

func WithLimit

func WithLimit(n int64) OpOption

WithLimit limits the number of results to return from 'Get' request. If WithLimit is given a 0 limit, it is treated as no limit.

func WithPrefix

func WithPrefix() OpOption

WithPrefix enables 'Get', 'Delete', or 'Watch' requests to operate on the keys with matching prefix. For example, 'Get(foo, WithPrefix())' can return 'foo1', 'foo2', and so on.

func WithPrevKV

func WithPrevKV() OpOption

WithPrevKV gets the previous key-value pair before the event happens. If the previous KV is already compacted, nothing will be returned.

func WithRange

func WithRange(endKey string) OpOption

WithRange specifies the range of 'Get', 'Delete', 'Watch' requests. For example, 'Get' requests with 'WithRange(end)' returns the keys in the range [key, end). endKey must be lexicographically greater than start key.

func WithRev

func WithRev(rev int64) OpOption

WithRev specifies the store revision for 'Get' request. Or the start revision of 'Watch' request.

func WithSerializable

func WithSerializable() OpOption

WithSerializable makes 'Get' request serializable. By default, it's linearizable. Serializable requests are better for lower latency requirement.

type PutResponse

type PutResponse pb.PutResponse

type Txn

type Txn interface {
	// If takes a list of comparison. If all comparisons passed in succeed,
	// the operations passed into Then() will be executed. Or the operations
	// passed into Else() will be executed.
	If(cs ...Cmp) Txn

	// Then takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() succeed.
	Then(ops ...Op) Txn

	// Else takes a list of operations. The Ops list will be executed, if the
	// comparisons passed in If() fail.
	Else(ops ...Op) Txn

	// Commit tries to commit the transaction.
	Commit() (*TxnResponse, error)
}

type TxnResponse

type TxnResponse pb.TxnResponse

type WatchChan

type WatchChan <-chan WatchResponse

type WatchResponse

type WatchResponse struct {
	Header pb.ResponseHeader
	Events []*Event

	// CompactRevision is the minimum revision the watcher may receive.
	CompactRevision int64

	// Canceled is used to indicate watch failure.
	// If the watch failed and the stream was about to close, before the channel is closed,
	// the channel sends a final response that has Canceled set to true with a non-nil Err().
	Canceled bool

	// Created is used to indicate the creation of the watcher.
	Created bool
	// contains filtered or unexported fields
}

func NewWatchResponseErr

func NewWatchResponseErr(err error) WatchResponse

func (*WatchResponse) Err

func (wr *WatchResponse) Err() error

Err is the error value if this WatchResponse holds an error.

func (*WatchResponse) IsProgressNotify

func (wr *WatchResponse) IsProgressNotify() bool

IsProgressNotify returns true if the WatchResponse is progress notification.

type Watcher

type Watcher interface {
	// Watch watches on a key or prefix. The watched events will be returned
	// through the returned channel. If revisions waiting to be sent over the
	// watch are compacted, then the watch will be canceled by the server, the
	// client will post a compacted error watch response, and the channel will close.
	Watch(ctx context.Context, key string, opts ...OpOption) WatchChan

	// Close closes the watcher and cancels all watch requests.
	Close() error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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