Skip to content

Instantly share code, notes, and snippets.

@mcpaddy
Created August 27, 2015 21:53
Show Gist options
  • Save mcpaddy/15f7b27c76376d47962d to your computer and use it in GitHub Desktop.
Save mcpaddy/15f7b27c76376d47962d to your computer and use it in GitHub Desktop.
from couchbase import Couchbase
from couchbase.exceptions import CouchbaseError
c = Couchbase.connect(bucket='beer-sample', host='localhost')
try:
beer = c.get("aass_brewery-juleol")
except CouchbaseError as e:
print "Couldn't retrieve value for key", e
# Rethrow the exception, making the application exit
raise
doc = beer.value
# Because Python 2.x will complain if an ASCII format string is used
# with Unicode format values, we make the format string unicode as well.
print unicode("{name}, ABV: {abv}").format(name=doc['name'], abv=doc['abv'])
doc['comment'] = "Random beer from Norway"
try:
result = c.replace("aass_brewery-juleol", doc, cas=beer.cas)
print result
except CouchbaseError as e:
print "Couldn't replace key"
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment