David, 

Adding to what Michael said, an idiomatic pattern I've been using is:

obj = kv.bucket(b).get(name)
data = f.get_data() or {'my_list': []}
data['my_list'].append(something)

obj.set_data(data)
obj.store()


[usually it's `f.get_data() or {}` when I use it, but you should see the 
pattern.]

Hope that helps save a couple lines at a time,
-- 
Adam Lindsay


On Saturday, 29 September 2012 at 03:23, David Lowell wrote:

> Hi folks,
> 
> Simple question here. Based on the python client documentation, I'm unclear 
> on the canonical means to perform in python a read-modify-write cycle on an 
> object stored in Riak. 
> 
> What seems intuitive to me:
> 
> obj = kv.bucket(b).get(name)
> if f.exists():
> data = f.get_data()
> # todo: check for siblings, and resolve
> else:
> data = {'my_list': []}
> data['my_list'].append(something) 
> 
> obj.set_data(data)
> obj.store()
> 
> My assumption here is that the RiakObject 'obj' has internally kept the 
> vector clock for this key, and when this update gets stored, it will do the 
> right thing. However, the documentation doesn't say that's what will happen. 
> In fact, I can't find anything in the documentation that makes it clear how 
> to do this read-modify-write.
> 
> There is this piece of documentation for the python client API:
> 
> | populate(self, Result)
> | Populate the object based on the return from get.
> |
> | If None returned, then object is not found
> | If a tuple of vclock, contents then one or more
> | whole revisions of the key were found
> | If a list of vtags is returned there are multiple
> | sibling that need to be retrieved with get.
> 
> This is obviously not very clear. This sounds like it has something to do 
> with read-modify-write, but who knows.
> 
> So, is my intuition in the code above correct? Or should we write back a 
> modified object through some other means like populate()?
> 
> Thanks for the guidance,
> 
> Dave
> 
> --
> Dave Lowell
> [email protected] (mailto:[email protected])
> 
> 
> _______________________________________________
> riak-users mailing list
> [email protected] (mailto:[email protected])
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> 
> 


_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to