MCPcopy
hub / github.com/etcd-io/etcd / ExampleKeyExists

Function ExampleKeyExists

client/v3/clientv3util/example_key_test.go:48–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func ExampleKeyExists() {
49 cli, err := clientv3.New(clientv3.Config{
50 Endpoints: []string{"127.0.0.1:2379"},
51 })
52 if err != nil {
53 log.Fatal(err)
54 }
55 defer cli.Close()
56 kvc := clientv3.NewKV(cli)
57
58 // perform a delete only if key already exists
59 _, err = kvc.Txn(context.Background()).
60 If(clientv3util.KeyExists("purpleidea")).
61 Then(clientv3.OpDelete("purpleidea")).
62 Commit()
63 if err != nil {
64 log.Fatal(err)
65 }
66}

Callers

nothing calls this directly

Calls 6

TxnMethod · 0.95
FatalMethod · 0.65
CloseMethod · 0.65
CommitMethod · 0.65
ThenMethod · 0.65
IfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…