Skip to content

Instantly share code, notes, and snippets.

@yichengq
Created May 9, 2014 20:57
Show Gist options
  • Save yichengq/5504aea2fb24704667da to your computer and use it in GitHub Desktop.
Save yichengq/5504aea2fb24704667da to your computer and use it in GitHub Desktop.
yichengq@1 ~/D/etcd2> curl http://127.0.0.1:4001/v2/keys/foo -XPUT -d value=bar
{"action":"set","node":{"key":"/foo","value":"bar","modifiedIndex":45,"createdIndex":45},"prevNode":{"key":"/foo","value":"bbbar","modifiedIndex":8,"createdIndex":8}}%
yichengq@1 ~/D/etcd2> curl http://127.0.0.1:4001/v2/keys/foo\?prevValue\=bar -XPUT -d value=bar2
{"action":"compareAndSwap","node":{"key":"/foo","value":"bar2","modifiedIndex":46,"createdIndex":45},"prevNode":{"key":"/foo","value":"bar","modifiedIndex":45,"createdIndex":45}}%
yichengq@1 ~/D/etcd2> curl http://127.0.0.1:4001/v2/keys/foo\?prevValue\=bar -XPUT -d value=bar2
{"errorCode":101,"message":"Compare failed","cause":"[bar != bar2]","index":46}
@alexanderkjeldaas
Copy link

$ curl -XPUT http://localhost:4001/v2/keys/test\?prevExists\=false -d 'value=three'
{"action":"set","node":{"key":"/test","value":"three","modifiedIndex":45,"createdIndex":45},"prevNode":{"key":"/test","value":"2","modifiedIndex":44,"createdIndex":43}}
$ curl -XPUT http://localhost:4001/v2/keys/test\?prevExists\=false -d 'value=three'
{"action":"set","node":{"key":"/test","value":"three","modifiedIndex":46,"createdIndex":46},"prevNode":{"key":"/test","value":"three","modifiedIndex":45,"createdIndex":45}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment