Skip to content

Commit

Permalink
Add CAS mismatch example to python docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mnunberg committed May 5, 2014
1 parent 36d7a64 commit df302f9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Python/04_retrieve.py
Expand Up @@ -3,6 +3,7 @@

import os
from couchbase import Couchbase
from couchbase.exceptions import KeyExistsError
from blessings import Terminal
import json
import hashlib
Expand Down Expand Up @@ -63,17 +64,24 @@ def parse_json( val ):
print
kv = cb.get(user_data1["email"])
print kv
print "cas = " + str(kv.cas)

print t.bold_red("--------------------------------------------------------------------------")
print t.bold_red("Update doc and look at cas")
print

kv.value["logins"] += 1
cb.replace(kv.value["email"], kv.value)
cb.replace(kv.value["email"], kv.value, cas=kv.cas)

kv = cb.get(user_data1["email"])
print kv
print "cas = " + str(kv.cas)


print t.bold_red("--------------------------------------------------------------------------")
print t.bold_red("Data Consistency: Try to update with invalid CAS")
print ""
try:
cb.replace(kv.value["email"], kv.value, cas=0xdeadbeef)
except KeyExistsError as e:
print e

print t.bold_red("--------------------------------------------------------------------------")

0 comments on commit df302f9

Please sign in to comment.