Created
January 9, 2015 16:25
-
-
Save areski/83af76ff0373b4c1a1b1 to your computer and use it in GitHub Desktop.
Play with Riak - Python
This file contains 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
# | |
# Play with Riak | |
# | |
import riak | |
myClient = riak.RiakClient(pb_port=8087, protocol='pbc') | |
myBucket = myClient.bucket('test') | |
val1 = 1 | |
key1 = myBucket.new('one', data=val1) | |
key1.store() | |
val2 = "two" | |
key2 = myBucket.new('two', data=val2) | |
key2.store() | |
val3 = {"myValue": 3} | |
key3 = myBucket.new('three', data=val3) | |
key3.store() | |
print "Featch from Riak\n-------------------------\n\n" | |
fetched1 = myBucket.get('one') | |
fetched2 = myBucket.get('two') | |
fetched3 = myBucket.get('three') | |
print (fetched1, fetched2, fetched3) | |
assert val1 == fetched1.data | |
assert val2 == fetched2.data | |
assert val3 == fetched3.data | |
# Update | |
fetched3.data["myValue"] = 42 | |
fetched3.store() | |
fetched1.delete() | |
fetched2.delete() | |
fetched3.delete() | |
assert myBucket.get('one').exists == False | |
assert myBucket.get('two').exists == False | |
assert myBucket.get('three').exists == False | |
book = { | |
'isbn': "1111979723", | |
'title': "Moby Dick", | |
'author': "Herman Melville", | |
'body': "Call me Ishmael. Some years ago...", | |
'copies_owned': 3 | |
} | |
booksBucket = myClient.bucket('books') | |
newBook = booksBucket.new(book['isbn'], data=book) | |
newBook.store() | |
print "fetchedBook\n-------------------------\n\n" | |
fetchedBook = booksBucket.get(book['isbn']) | |
print(fetchedBook.encoded_data) | |
print(fetchedBook.data) | |
fetchedBook.delete() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment