etcd之curl请求介绍

version

[root@test-go etcd-v3.1.5-linux-amd64]# curl 127.0.0.1:2379/version
{"etcdserver":"3.1.5","etcdcluster":"3.1.0"}[root@test-go etcd-v3.1.5-linux-amd64]#

set

etcdctl set key value 
[root@test-go etcd-v3.1.5-linux-amd64]# curl -X PUT http://localhost:2379/v2/keys/mykey -d value=myvalue
{"action":"set","node":{"key":"/mykey","value":"myvalue","modifiedIndex":7,"createdIndex":7}}
[root@test-go etcd-v3.1.5-linux-amd64]#
  • 设置有效时间
curl -X PUT http://localhost:2379/v2/keys/mykey -d value=ok -d ttl=100

get

etcdctl get key 
[root@test-go etcd-v3.1.5-linux-amd64]# curl -X GET http://localhost:2379/v2/keys/mykey
{"action":"get","node":{"key":"/mykey","value":"myvalue","modifiedIndex":7,"createdIndex":7}}

rm

etcdctl rm key 
[root@test-go etcd-v3.1.5-linux-amd64]# curl -X DELETE http://localhost:2379/v2/keys/mykey
{"action":"delete","node":{"key":"/mykey","modifiedIndex":8,"createdIndex":7},"prevNode":{"key":"/mykey","value":"myvalue","modifiedIndex":7,"createdIndex":7}}
[root@test-go etcd-v3.1.5-linux-amd64]# curl -X GET http://localhost:2379/v2/keys/mykey
{"errorCode":100,"message":"Key not found","cause":"/mykey","index":8}