From cc9c75acbee32b042ebf8af0e1ef455eae35832c Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Sat, 30 Nov 2013 22:46:12 -0800 Subject: [PATCH 1/2] fix(README): repair some noisy spaces --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d38186bd..0cc358d61 100644 --- a/README.md +++ b/README.md @@ -219,9 +219,9 @@ The watch command returns immediately with the same response as previous. ### Atomic Compare-and-Swap (CAS) -Etcd can be used as a centralized coordination service in a cluster and `CompareAndSwap` is the most basic operation to build distributed lock service. +Etcd can be used as a centralized coordination service in a cluster and `CompareAndSwap` is the most basic operation to build distributed lock service. -This command will set the value of a key only if the client-provided conditions are equal to the current conditions. +This command will set the value of a key only if the client-provided conditions are equal to the current conditions. The current comparable conditions are: From 1d02a70802637b4940938314e0058763ea6b18d8 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Sun, 1 Dec 2013 13:28:08 -0800 Subject: [PATCH 2/2] feat(README): add a prevExist example On the mailing list Dustin Oprea suggested adding a prevExist concrete example would make it more clear that the value must be true or false. --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cc358d61..3db3f8642 100644 --- a/README.md +++ b/README.md @@ -238,8 +238,20 @@ Let's create a key-value pair first: `foo=one`. curl -L http://127.0.0.1:4001/v2/keys/foo -XPUT -d value=one ``` -Let's try an invalid `CompareAndSwap` command first. -We can provide the `prevValue` parameter to the set command to make it a `CompareAndSwap` command. +Let's try some invalid `CompareAndSwap` commands first. + +Trying to set this existing key with `prevExist=false` fails as expected: +```sh +curl -L http://127.0.0.1:4001/v2/keys/foo?prevExist=false -XPUT -d value=three +``` + +The error code explains the problem: + +```json +{"errorCode":105,"message":"Already exists","cause":"/foo","index":39776} +``` + +Now lets provide a `prevValue` parameter: ```sh curl -L http://127.0.0.1:4001/v2/keys/foo?prevValue=two -XPUT -d value=three