lericson/pylibmc — pull request #77 by jhansche (2012-02-16 17:47:47+00:00)
Title: MEMCACHED_BEHAVIOR_TCP_KEEPALIVE and MEMCACHED_CALLBACK_PREFIX_KEY

pylibmc currently supports a "key_prefix" option in cache gets and sets, but that must be done manually on every request. libmemcached supports a prefix key "callback", which allows libmemcached to do the JIT modifications to the cache keys.

To keep the implementation simple, I've inserted the callbacks into the set_behaviors() functionality, so that it works more like pecl-memcached's setOption() feature, which can do behaviors, callbacks, and set internal extension options.

This commit also adds the "tcp_keepalive" behavior.

>>> c = pylibmc.Client(servers=['127.0.0.1'])
>>> c.set('foo:bar', 'This is set as foo:bar.')
True
>>> c.set('bar', 'This is set as bar.')
True
>>> c.set_behaviors({"prefix_key": "foo:"})
>>> print c.get('foo:bar')
None
>>> c.get('bar')
'This is set as foo:bar.'