Documentation ¶
Index ¶
- Constants
- type Conn
- func (conn *Conn) CheckLeaseGrantExists(ctx context.Context, leaseID clientv3.LeaseID) (bool, error)
- func (conn *Conn) Close() error
- func (conn *Conn) Delete(ctx context.Context, key string) (*clientv3.DeleteResponse, error)
- func (conn *Conn) DeleteWithPrefix(ctx context.Context, key string) (*clientv3.DeleteResponse, error)
- func (conn *Conn) GetLeaseIDByKey(key string) (clientv3.LeaseID, error)
- func (conn *Conn) LockEtcdMutex(ctx context.Context, mutexKey, mutexValue string, ttl int64) (bool, error)
- func (conn *Conn) PutWithTTL(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)
- func (conn *Conn) PutWithTTLAndKeepAlive(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, <-chan *clientv3.LeaseKeepAliveResponse, error)
- func (conn *Conn) PutWithTTLAndKeepAliveOnce(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)
- func (conn *Conn) UnlockEtcdMutex(ctx context.Context, mutexKey string) (*clientv3.LeaseRevokeResponse, error)
Constants ¶
const ( DefaultConnectTimeOut = 10 * time.Second DefaultMutexLeaseSeconds = 3600 MaxTTL = 3600 * 24 MinimumTTL = 2 ZeroRevision = 0 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { Endpoints []string KeyLeaseIDMap sync.Map clientv3.Config clientv3.Client clientv3.Lease }
func NewEtcdConn ¶
NewEtcdConn returns connection to etcd, it uses client v3 library api
func NewEtcdConnWithConnectTimeout ¶ added in v0.1.1
NewEtcdConnWithConnectTimeout returns connection to etcd, it uses client v3 library api
func (*Conn) CheckLeaseGrantExists ¶
func (*Conn) Delete ¶
Delete delete the key, but does NOT revoke the concerned lease because the lease may be assigned to other keys.
func (*Conn) DeleteWithPrefix ¶
func (conn *Conn) DeleteWithPrefix(ctx context.Context, key string) (*clientv3.DeleteResponse, error)
DeleteWithPrefix delete the keys of which name started with the given key, but does NOT revoke the concerned lease because the lease may be assigned to other keys.
func (*Conn) GetLeaseIDByKey ¶
GetLeaseIDByKey returns lease response by mutex key name which was maintained when successfully get the mutex
func (*Conn) LockEtcdMutex ¶
func (conn *Conn) LockEtcdMutex(ctx context.Context, mutexKey, mutexValue string, ttl int64) (bool, error)
LockEtcdMutex tries to get a distributed mutex from etcd, if success, return true, nil
func (*Conn) PutWithTTL ¶
func (conn *Conn) PutWithTTL(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)
PutWithTTL is an alias of PutWithTTLAndKeepAliveOnce
func (*Conn) PutWithTTLAndKeepAlive ¶
func (conn *Conn) PutWithTTLAndKeepAlive(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, <-chan *clientv3.LeaseKeepAliveResponse, error)
PutWithTTLAndKeepAlive put the key and value and keep alive the lease with given ttl
func (*Conn) PutWithTTLAndKeepAliveOnce ¶
func (conn *Conn) PutWithTTLAndKeepAliveOnce(ctx context.Context, key, value string, ttl int64) (*clientv3.PutResponse, *clientv3.LeaseKeepAliveResponse, error)
PutWithTTLAndKeepAliveOnce put the key and value and refresh the lease with given ttl once.
func (*Conn) UnlockEtcdMutex ¶
func (conn *Conn) UnlockEtcdMutex(ctx context.Context, mutexKey string) (*clientv3.LeaseRevokeResponse, error)
UnlockEtcdMutex release the distributed mutex