while True:
    obj = memcache_client.gets(key)
assert obj is not None, 'Uninitialized object'
if memcache_client.cas(key, obj + ['D']):
    break
How to add an item to a memcached list atomically (in Python)