Twisted SupportΒΆ
pyrakoon comes with an AbstractClient
implementation
supporting the Twisted framework, provided as a
Protocol
in the pyrakoon.tx
module.
Here’s a demonstration of how it could be used:
>>> from twisted.internet import defer, endpoints, reactor
>>> from pyrakoon import client, tx
>>> class Protocol(tx.ArakoonProtocol, client.ClientMixin): pass
>>> @defer.inlineCallbacks
... def connected(proto):
... yield proto.set('key', 'value')
... value = yield proto.get('key')
... print 'Value:', value
... yield proto.delete('key')
... reactor.stop()
>>> endpoint = endpoints.TCP4ClientEndpoint(reactor, 'localhost', 4000)
>>> d = endpoints.connectProtocol(endpoint, Protocol('ricky'))
>>> d.addCallback(connected)
<Deferred at ...>
>>> reactor.run()
Value: value