jaysonsantos/python-binary-memcached — pull request #24 by zewt (2014-02-10 22:21:37+00:00)
Title: Implement CAS.

This is a critical part of memcached usage.

- The API follows the pattern set by pylibmc, where CAS values are returned to the caller, and not python-memcache, which magically caches values internally. It's simpler and much more obvious, where in python-memcache you have to enable it explicitly (since it leaks if you're not aware of it) and periodically flush the cache.

- Performing a CAS with a cas value of None is equivalent to an add. This is logically doing a compare-and-set saying "compare against the lack of a value". The common pattern is wanting to set a value as long as nobody else has written something since you read its value, so if you read that the item didn't exist, CAS becomes ADD.

- Multi-CAS is supported through set_multi, as well as performing some updates with CAS and some not in a single batch:

...
mc.set_multi({
('key', cas): value1,
('key2', cas2): value2,
'key3': value,
}]
...

- The cas() API is redundant with set_multi, but was added for parity with other Python memcache clients. I'm not sure if this is actually worth having.

- delete() supports CAS.