etcdstore

package
v0.0.0-...-2e8ce5b Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

====================================================

# Copyright (C)2019 All rights reserved. # # Author : domchan # Email : 814172254@qq.com # File Name : etcd.go # Created : 2019-01-29 11:48:14 # Describe : # # ====================================================

Index

Constants

View Source
const (

	// DefaultLockKey 锁的默认key
	DefaultLockKey = "mutex/lock/key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Etcd

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

Etcd implements Store

func New

func New(addrs []string, options *store.Config) (*Etcd, error)

New 通过给定的地址列表和tls配置,创建一个新的etcd客户端

func (*Etcd) AtomicDelete

func (s *Etcd) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, *store.KVPair, error)

AtomicDelete 删除该键的值,如果这个键被同时修改,抛出一个错误

func (*Etcd) AtomicPut

func (s *Etcd) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, opts *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut 更新一个值在“键”,如果被键同时修改,则抛出错误 如果操作失败,它将返回(false, previous, error (if err != nil)) 如果操作成功,它将返回(true, nil, nil)

func (*Etcd) Close

func (s *Etcd) Close() error

Close 关闭客户端连接

func (*Etcd) Delete

func (s *Etcd) Delete(ctx context.Context, key string) error

Delete 删除这个key和它的值

func (*Etcd) DeleteTree

func (s *Etcd) DeleteTree(ctx context.Context, directory string) error

DeleteTree 产出directory下所有的键值

func (*Etcd) Exists

func (s *Etcd) Exists(ctx context.Context, key string) (bool, error)

Exists 查看该key是否存在在etcd中

func (*Etcd) Get

func (s *Etcd) Get(ctx context.Context, key string) (*store.KVPair, error)

Get 获取一个key的值和它最后一次修改的版本号 这个版本号用来Atomic操作时的cas

func (*Etcd) List

func (s *Etcd) List(ctx context.Context, directory string) ([]*store.KVPair, error)

List 列出该directory下的所有kv

func (*Etcd) NewLock

func (s *Etcd) NewLock(key string, options *store.LockOptions) (store.Locker, error)

NewLock 返回一个所得结构体,可以用来锁住一个key

func (*Etcd) NewNonBlockLocker

func (s *Etcd) NewNonBlockLocker(key string, options *store.LockOptions) store.NonBlockLocker

NewNonBlockLocker 返回一个非阻塞分布式锁

func (*Etcd) Put

func (s *Etcd) Put(ctx context.Context, key string, value []byte, opts *store.WriteOptions) error

Put 更新该key的value,如果超时时间<=0,则没有超时时间

func (*Etcd) Watch

func (s *Etcd) Watch(ctx context.Context, key string, stopCh <-chan struct{}) (<-chan *store.WatchRes, error)

Watch 观察一个key的变化 它返回一个chan可以用来接收该key的value的变化 向stopch中传值可以终止watch

func (*Etcd) WatchTree

func (s *Etcd) WatchTree(ctx context.Context, directory string, stopCh <-chan struct{}) (<-chan *store.WatchRes, error)

WatchTree 监视“目录”上的更改 它返回一个chan可以用来接收directory下kv的变化 向stopch中传值可以终止watchtree

Jump to

Keyboard shortcuts

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