mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix v1 handler: use create command when test against prevexistence
This commit is contained in:
parent
7fa99b3794
commit
28722e2127
@ -30,12 +30,20 @@ func SetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
|||||||
|
|
||||||
// If the "prevValue" is specified then test-and-set. Otherwise create a new key.
|
// If the "prevValue" is specified then test-and-set. Otherwise create a new key.
|
||||||
var c raft.Command
|
var c raft.Command
|
||||||
if prevValueArr, ok := req.Form["prevValue"]; ok && len(prevValueArr) > 0 {
|
if prevValueArr, ok := req.Form["prevValue"]; ok {
|
||||||
c = &store.CompareAndSwapCommand{
|
if len(prevValueArr) > 0 { // test against previous value
|
||||||
Key: key,
|
c = &store.CompareAndSwapCommand{
|
||||||
Value: value,
|
Key: key,
|
||||||
PrevValue: prevValueArr[0],
|
Value: value,
|
||||||
ExpireTime: expireTime,
|
PrevValue: prevValueArr[0],
|
||||||
|
ExpireTime: expireTime,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c = &store.CreateCommand{ // test against existence
|
||||||
|
Key: key,
|
||||||
|
Value: value,
|
||||||
|
ExpireTime: expireTime,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -55,13 +55,16 @@ func (event *Event) Response() interface{} {
|
|||||||
Expiration: event.Expiration,
|
Expiration: event.Expiration,
|
||||||
}
|
}
|
||||||
|
|
||||||
if response.Action == Create || response.Action == Set {
|
if response.Action == Set {
|
||||||
response.Action = "set"
|
|
||||||
if response.PrevValue == "" {
|
if response.PrevValue == "" {
|
||||||
response.NewKey = true
|
response.NewKey = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if response.Action == CompareAndSwap || response.Action == Create {
|
||||||
|
response.Action = "testAndSet"
|
||||||
|
}
|
||||||
|
|
||||||
return response
|
return response
|
||||||
} else {
|
} else {
|
||||||
responses := make([]*Response, len(event.KVPairs))
|
responses := make([]*Response, len(event.KVPairs))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user