Created
August 27, 2015 21:53
-
-
Save mcpaddy/15f7b27c76376d47962d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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