transitorykris/etcd-py — pull request #20 by tarnfeld (2013-12-06 17:24:19+00:00)
Title: Implemened an append-only linked list

In some use cases (lots of risk of race conditions) an append-only list is pretty handy. An alternative way of representing an ordered list of values in `etcd` would be a JSON blob (or something serialized) but that requires the client adding an item to the list has to re-write everything. If two clients are appending something to the list, one will overwrite the other.

You could get around this by using `prevValue` and re-attempting the write in the event of inconsistency but if you have a list with a lot of items, this can become problematic.

```python
>>> import etcd
>>> e = etcd.Etcd()
>>> e.set_list("my_key", ["a", "b"])
EtcdSetList(index=94, head=EtcdSet(index=94, newKey=False, prevValue=u'a', expiration=None), values=['a', 'b'])
>>> e.get_list("my_key")
EtcdGetList(head=EtcdSet(index=94, value=u'b'), index=94, values=[u'a', u'b'])
>>> e.append("my_key", "c")
EtcdSet(index=95, newKey=False, prevValue=u'b', expiration=None)
>>> e.append("my_key", "d")
EtcdSet(index=96, newKey=False, prevValue=u'c', expiration=None)
>>> e.get_list("my_key")
EtcdGetList(head=EtcdSet(index=96, value=u'd'), index=96, values=[u'a', u'b', u'c', u'd'])
>>> e.get_list("my_key", 2)
EtcdGetList(head=EtcdSet(index=96, value=u'd'), index=96, values=[u'c', u'd'])
```