Documentation
¶
Index ¶
- Variables
- func NewProvider(ctx context.Context, c *Client, key, value string, ttl int64, f ProviderFunc) error
- func NewProviderKey(preifx, host string, debug bool) (k, v string)
- type Client
- func (cli *Client) AddMember(ctx context.Context, peerURLs []string) error
- func (cli *Client) Close() error
- func (cli *Client) Compact(ctx context.Context, threshold int64, isdefrag bool)
- func (cli *Client) CreateLeaseID(ctx context.Context, ttl int64) (int64, error)
- func (cli *Client) DelMember(ctx context.Context, memberID uint64) error
- func (cli *Client) Delete(ctx context.Context, key string) error
- func (cli *Client) DeleteWithPrefix(ctx context.Context, key string) error
- func (cli *Client) DestroyLock(ctx context.Context, key string)
- func (cli *Client) Get(ctx context.Context, prefix string) ([]string, error)
- func (cli *Client) GetKeys(ctx context.Context, prefix string) ([]string, error)
- func (cli *Client) GetKvs(ctx context.Context, prefix string) (map[string]string, error)
- func (cli *Client) GetLimit(ctx context.Context, prefix string, offset int64) ([]string, []string, error)
- func (cli *Client) GetOne(ctx context.Context, prefix string) (string, error)
- func (cli *Client) GetPriorityQueueList(ctx context.Context, key string) ([]string, error)
- func (cli *Client) GetTTLWithLease(ctx context.Context, leaseID int64) (int64, error)
- func (cli *Client) KeepAliveOnce(ctx context.Context, leaseID int64) error
- func (cli *Client) ListMembers(ctx context.Context) ([]*Member, error)
- func (cli *Client) Lock(ctx context.Context, key string) error
- func (cli *Client) NewElection(ctx context.Context, key string, conf *ElectionConfig, f ElectionFunc) error
- func (cli *Client) NewWatcher(ctx context.Context, prefix string, f WatcherFunc) error
- func (cli *Client) Pop(ctx context.Context, prefix string, limit int64) ([]string, error)
- func (cli *Client) Put(ctx context.Context, key, value string) (err error)
- func (cli *Client) PutWithLease(ctx context.Context, key, value string, lease int64) error
- func (cli *Client) PutWithTTL(ctx context.Context, key, value string, ttl int64) (err error)
- func (cli *Client) UnLock(ctx context.Context, key string) error
- func (cli *Client) WithNodeName(name string) *Client
- type Election
- type ElectionConfig
- type ElectionFunc
- type EventType
- type Member
- type OptionFunc
- type PriorityQueue
- type Provider
- type ProviderFunc
- type UpdateEvent
- type Watcher
- type WatcherFunc
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidParam = errors.New("invalid param")
)
Functions ¶
func NewProvider ¶
func NewProvider(ctx context.Context, c *Client, key, value string, ttl int64, f ProviderFunc) error
NewProvider 创建一个Provider.
func NewProviderKey ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AddMember ¶
AddMember 增加节点.例如: peerURLs=[]string{"http://127.0.0.1:2180"}
func (*Client) CreateLeaseID ¶
CreateLeaseID 创建租期ID
func (*Client) DeleteWithPrefix ¶
DeleteDeleteWithPrefix 使用前缀删除一批Key
func (*Client) GetLimit ¶
func (cli *Client) GetLimit(ctx context.Context, prefix string, offset int64) ([]string, []string, error)
GetLimit 从ETCD中通过前缀获得,所以有可能有多个值
func (*Client) GetPriorityQueueList ¶
GetPriorityQueueList 获取指定前缀的优先级队列名称
func (*Client) GetTTLWithLease ¶
GetTTLWithLease 获取租约TTL
func (*Client) KeepAliveOnce ¶
KeepAliveOnce 给租约进行保活
func (*Client) ListMembers ¶
ListMembers 节点成员
func (*Client) NewElection ¶
func (cli *Client) NewElection(ctx context.Context, key string, conf *ElectionConfig, f ElectionFunc) error
NewElection 通过ETCD Client创建一个Election.
func (*Client) NewWatcher ¶
NewWatcher 通过ETCD Client创建一个Watcher对象,需要输入监听的前缀. 异步的
func (*Client) PutWithLease ¶
PutWithLease 使用租期ID创建数据
func (*Client) PutWithTTL ¶
PutWithTTL 向ETCD写入一个带TTL的Key.
func (*Client) WithNodeName ¶
type Election ¶
type Election struct {
// contains filtered or unexported fields
}
Election 用来进行选举,如果成功,就会通过回调函数返回选举成功,默认情况下,当前节点不是主节点.
type ElectionConfig ¶
type ElectionConfig struct {
Timeout int `json:"timeout"`
}
type ElectionFunc ¶
ElectionFunc 选举成功之后会回调这个函数,只会回调一次.
type Member ¶
type Member struct { // name is the human-readable name of the member. If the member is not started, the name will be an empty string. Name string `json:"name,omitempty"` // peerURLs is the list of URLs the member exposes to the cluster for communication. PeerURLs []string `json:"peerURLs,omitempty"` ClientURLs []string `json:"clientURLs,omitempty"` // ID is the member ID for this member. ID uint64 `json:"ID,omitempty"` }
type OptionFunc ¶
func WithDialKeepAliveTime ¶
func WithDialKeepAliveTime(time time.Duration) OptionFunc
WithDialKeepAliveTime 客户端超时时间
type PriorityQueue ¶
type PriorityQueue struct {
// contains filtered or unexported fields
}
func NewPriorityQueue ¶
func NewPriorityQueue(ctx context.Context, endpoints []string, key string, ops ...OptionFunc) (*PriorityQueue, error)
func (*PriorityQueue) Delete ¶
func (p *PriorityQueue) Delete(ctx context.Context) error
Delete 删除这个优先级队列的所有记录
func (*PriorityQueue) Len ¶
func (p *PriorityQueue) Len(ctx context.Context) (int, error)
Len 获取优先级队列的剩余元素
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider 注册一个Key,并且随时保持心跳,对象同样有Start和Stop函数.
type ProviderFunc ¶
type UpdateEvent ¶
type UpdateEvent struct { Key string Value string PreKey string PreValue string EventType EventType }
func (UpdateEvent) String ¶
func (ue UpdateEvent) String() string
type WatcherFunc ¶
type WatcherFunc func(w *Watcher, updateEvent []*UpdateEvent, err error)
WatcherFunc 来自于Watcher的回调,通过这个回调来进行通知.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.