如何学习一门新技术,十年 MarkDown 程序员怎么做

37 阅读1分钟

介绍

谈使用场景之前,看看他有哪些功能

官方定义是这样的: etcd is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines. It gracefully handles leader elections during network partitions and can tolerate machine failure, even in the leader node.

使用场景

  • 服务发现

  • 配置中心

  • 分布式锁

安装&搭建

搭建 ETCD

环境: mac

# 安装
brew install etcd

# 启动
brew services start etcd

# 检查状态
brew services list | grep etcd

# 停止
brew services stop etcd

# 卸载
brew uninstall etcd

与 ETCD 交互

# 检查工具是否安装
etcdctl version

# 写入
etcdctl put mykey "myvalue"

# 获取
etcdctl get mykey

# 删除
etcdctl del mykey

集群

# 查看集群状态
etcdctl cluster-health

Go+ETCD 编码

安装依赖

go get go.etcd.io/etcd/client/v3

编码

github.com/Rodert/go-d…

执行

go run main.go

执行结果: