contrib/recipes/key.go
func putNewKV(kv v3.KV, key, val string, leaseID v3.LeaseID) (int64, error) {
	cmp := v3.Compare(v3.Version(key), "=", 0)
	req := v3.OpPut(key, val, v3.WithLease(leaseID))
	txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit()
	if err != nil {
		return 0, err
	}
	if !txnresp.Succeeded {
		return 0, ErrKeyExists
	}
	return txnresp.Header.Revision, nil
}
func putNewKV(kv v3.KV, key, val string, leaseID v3.LeaseID) (int64, error) {
	cmp := v3.Compare(v3.Version(key), "=", 0)
	req := v3.OpPut(key, val, v3.WithLease(leaseID))
	txnresp, err := kv.Txn(context.TODO()).If(cmp).Then(req).Commit()
	if err != nil {
		return 0, err
	}
	if !txnresp.Succeeded {
		return 0, ErrKeyExists
	}
	return txnresp.Header.Revision, nil
}
func putNewKV ( kv v3 . KV , key , val string , leaseID v3 . LeaseID ) ( int64 , error ) { cmp := v3 . Compare ( v3 . Version ( key ) , " " , 0 ) req := v3 . OpPut ( key , val , v3 . WithLease ( leaseID ) ) txnresp , err := kv . Txn ( context . TODO ( ) ) . If ( cmp ) . Then ( req ) . Commit ( ) if err != nil { return 0 , err } if ! txnresp . Succeeded { return 0 , ErrKeyExists } return txnresp . Header . Revision , nil }
// putNewKV attempts to create the given key, only succeeding if the key did
// not yet exist.
putNewKV attempts to create the given key only succeeding if the key did not yet exist .