Etcd是高可用的k-v存储,可以配置共享和服务发现
类似于zookeeper和consul
提供restful的api接口
基于raft算法的强一致性,高可用的服务存储目录
使用
import (
"fmt"
"time"
"github.com/etcd-master/clientv3"
)
func main() {
client, err := clientv3.New(clientv3.Config{
Endpoints: []string{"lcoalhost:2379", "lcoalhost:23791", "lcoalhost:23792"},
DialTimeout: 5 * time.Second,
})
if err != nil {
fmt.Println("conn failed")
return
}
fmt.Println("conn succ")
defer client.Close()
}
场景:服务发现和服务注册,配置中心,分布式锁,master选举