Documentation ¶
Index ¶
- Constants
- Variables
- func GetPrefixRangeEnd(prefix string) string
- type Client
- type Cluster
- type Cmp
- type CompactOp
- type CompactOption
- type CompactResponse
- type CompareResult
- type CompareTarget
- type Config
- type DeleteResponse
- type Event
- type GetResponse
- type KV
- type Lease
- type LeaseGrantResponse
- type LeaseID
- type LeaseRevokeResponse
- type Op
- type OpOption
- type PutResponse
- type Txn
- type TxnResponse
- type WatchChan
- type WatchResponse
- type Watcher
Constants ¶
const ( EventTypeDelete = mvccpb.DELETE EventTypePut = mvccpb.PUT )
Variables ¶
var (
CloseDB func()
)
Functions ¶
func GetPrefixRangeEnd ¶
GetPrefixRangeEnd gets the range end of the prefix. 'Get(foo, WithPrefix())' is equal to 'Get(foo, WithRange(GetPrefixRangeEnd(foo))'.
Types ¶
type Client ¶
Client provides and manages an etcd v3 client session.
type Cmp ¶
func ModRevision ¶
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 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 LeaseRevokeResponse ¶
type LeaseRevokeResponse pb.LeaseRevokeResponse
type Op ¶
type Op struct {
// contains filtered or unexported fields
}
Op represents an Operation that kv can execute.
func (Op) IsCountOnly ¶
IsCountOnly returns whether countOnly is set.
func (Op) ValueBytes ¶
ValueBytes returns the byte slice holding the Op's value, if any.
func (*Op) WithValueBytes ¶
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 WithLimit ¶
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 ¶
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 ¶
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 }