package main
import (
"context"
"fmt"
v3 "github.com/coreos/etcd/clientv3"
)
func main() {
client, err := v3.New(v3.Config{
Endpoints: []string{"http://127.0.0.1:2379"},
})
if err != nil {
fmt.Println(err)
return
}
key := "/foo/bar/"
txn := client.Txn(context.TODO()).If(v3.Compare(v3.CreateRevision(key), "=", 0)).
Then(v3.OpPut(key, "foo"))
resp, err := txn.Commit()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp.Responses)
}
$ rm -rf default.etcd/
$ etcd --version
etcd Version: 3.3.2
Git SHA: c9d46ab37
Go Version: go1.9.4
Go OS/Arch: darwin/amd64
$ etcdctl version
etcdctl version: 3.3.2
API version: 3.3
$ etcd --debug=true
$ go run main.go $ ETCDCTL_API=3 etcdctl get /foo/bar/ --rev 0 $ ETCDCTL_API=3 etcdctl get /foo/bar/ --rev 1 $ ETCDCTL_API=3 etcdctl get /foo/bar/ --rev 2 why run once but put twice key? and skip revision 1 that keep revision 0 and revision 2. thanks.
[response_put:
/foo/bar/
foo
/foo/bar/
foothis is glide.yaml
package: hello
import:
- package: github.com/coreos/etcd
version: ^3.3.2
subpackages:
- clientv3
Revision is global counter. Rev 0 is default value (returns latest).
Your first put was on revision 2. So, get request with rev 2 is returning the correct value.
i see. that means rev 1 is not uses? thanks.
The very first revision of etcd store is 1 (without any data written yet).
thanks!
Most helpful comment
The very first revision of etcd store is 1 (without any data written yet).