clientv3

package
v2.3.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: Apache-2.0 Imports: 14 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAvailableEndpoints = errors.New("etcdclient: no available endpoints")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// KV is the keyvalue API for the client's connection.
	KV pb.KVClient
	// Lease is the lease API for the client's connection.
	Lease pb.LeaseClient
	// Watch is the watch API for the client's connection.
	Watch pb.WatchClient
	// Cluster is the cluster API for the client's connection.
	Cluster pb.ClusterClient
	// 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 NewFromURL

func NewFromURL(url string) (*Client, error)

NewFromURL creates a new etcdv3 client from a URL.

func (*Client) ActiveConnection

func (c *Client) ActiveConnection() *grpc.ClientConn

activeConnection returns the current in-use connection

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client's etcd connections.

func (*Client) Dial

func (c *Client) Dial(endpoint string) (*grpc.ClientConn, error)

Dial establishes a connection for a given endpoint using the client's config

func (*Client) Endpoints

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

Endpoints lists the registered endpoints for the client.

func (*Client) Errors

func (c *Client) Errors() (errs []error)

Errors returns all errors that have been observed since called last.

type Cluster

type Cluster interface {
	// MemberList lists the current cluster membership.
	MemberList(ctx context.Context) (*MemberListResponse, error)

	// MemberLeader returns the current leader member.
	MemberLeader(ctx context.Context) (*Member, error)

	// MemberAdd adds a new member into the cluster.
	MemberAdd(ctx context.Context, peerAddrs []string) (*MemberAddResponse, error)

	// MemberRemove removes an existing member from the cluster.
	MemberRemove(ctx context.Context, id uint64) (*MemberRemoveResponse, error)

	// MemberUpdate updates the peer addresses of the member.
	MemberUpdate(ctx context.Context, id uint64, peerAddrs []string) (*MemberUpdateResponse, error)
}

func NewCluster

func NewCluster(c *Client) Cluster

type Cmp

type Cmp pb.Compare

func Compare

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

func CreatedRevision

func CreatedRevision(key string) Cmp

func ModifiedRevision

func ModifiedRevision(key string) Cmp

func Value

func Value(key string) Cmp

func Version

func Version(key string) Cmp

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

	// RetryDialer chooses the next endpoint to use
	RetryDialer EndpointDialer

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration

	// TLS holds the client secure credentials, if any.
	TLS *transport.TLSInfo
}

type DeleteResponse

type DeleteResponse pb.DeleteRangeResponse

type EndpointDialer

type EndpointDialer func(*Client) (*grpc.ClientConn, error)

EndpointDialer is a policy for choosing which endpoint to dial next

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 optionallly 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) error

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

func NewKV

func NewKV(c *Client) KV

type Lease

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

	// Revoke revokes the given lease.
	Revoke(ctx context.Context, id lease.LeaseID) (*LeaseRevokeResponse, error)

	// KeepAlive keeps the given lease alive forever.
	KeepAlive(ctx context.Context, id lease.LeaseID) (<-chan *LeaseKeepAliveResponse, error)

	// KeepAliveOnce renews the lease once. In most of the cases, Keepalive
	// should be used instead of KeepAliveOnce.
	KeepAliveOnce(ctx context.Context, id lease.LeaseID) (*LeaseKeepAliveResponse, error)

	// Lease keeps internal routines and connections for efficient communication with etcd server.
	// After using Lease, call Close() to release all related resources.
	Close() error
}

func NewLease

func NewLease(c *Client) Lease

type LeaseCreateResponse

type LeaseCreateResponse pb.LeaseCreateResponse

type LeaseKeepAliveResponse

type LeaseKeepAliveResponse pb.LeaseKeepAliveResponse

type LeaseRevokeResponse

type LeaseRevokeResponse pb.LeaseRevokeResponse

type Member

type Member pb.Member

type MemberAddResponse

type MemberAddResponse pb.MemberAddResponse

type MemberListResponse

type MemberListResponse pb.MemberListResponse

type MemberRemoveResponse

type MemberRemoveResponse pb.MemberRemoveResponse

type MemberUpdateResponse

type MemberUpdateResponse pb.MemberUpdateResponse

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

type OpOption

type OpOption func(*Op)

func WithFromKey

func WithFromKey() OpOption

func WithLease

func WithLease(leaseID lease.LeaseID) OpOption

func WithLimit

func WithLimit(n int64) OpOption

func WithRange

func WithRange(endKey string) OpOption

func WithRev

func WithRev(rev int64) OpOption

func WithSerializable

func WithSerializable() OpOption

func WithSort

func WithSort(tgt SortTarget, order SortOrder) OpOption

type PutResponse

type PutResponse pb.PutResponse

type SortOption

type SortOption struct {
	Target SortTarget
	Order  SortOrder
}

type SortOrder

type SortOrder int
const (
	SortNone SortOrder = iota
	SortAscend
	SortDescend
)

type SortTarget

type SortTarget int
const (
	SortByKey SortTarget = iota
	SortByVersion
	SortByCreatedRev
	SortByModifiedRev
	SortByValue
)

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)
}

Tx.If(

Compare(Value(k1), ">", v1),
Compare(Version(k1), "=", 2)

).Then(

OpPut(k2,v2), OpPut(k3,v3)

).Else(

OpPut(k4,v4), OpPut(k5,v5)

).Commit()

type TxnResponse

type TxnResponse pb.TxnResponse

type WatchChan

type WatchChan <-chan WatchResponse

type WatchResponse

type WatchResponse struct {
	Header pb.ResponseHeader
	Events []*storagepb.Event
	// CompactRevision is set to the compaction revision that
	// caused the watcher to cancel.
	CompactRevision int64
}

type Watcher

type Watcher interface {
	// Watch watches on a single key. The watched events will be returned
	// through the returned channel.
	// If the watch is slow or the required rev is compacted, the watch request
	// might be canceled from the server-side and the chan will be closed.
	Watch(ctx context.Context, key string, rev int64) WatchChan

	// WatchPrefix watches on a prefix. The watched events will be returned
	// through the returned channel.
	// If the watch is slow or the required rev is compacted, the watch request
	// might be canceled from the server-side and the chan will be closed.
	WatchPrefix(ctx context.Context, prefix string, rev int64) WatchChan

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

func NewWatcher

func NewWatcher(c *Client) Watcher

Directories

Path Synopsis
Package integration implements tests built upon embedded etcd, and focuses on correctness of etcd client.
Package integration implements tests built upon embedded etcd, and focuses on correctness of etcd client.

Jump to

Keyboard shortcuts

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