-
Notifications
You must be signed in to change notification settings - Fork 9
Async Client
Ignacio Corderi edited this page May 6, 2014
·
3 revisions
The async client can be used in the same way as the blocking client.
import kinetic
c = kinetic.AsyncClient('localhost', 8123)
c.connect()
c.put('my_key', 'my_value')
print c.get('my_key')
c.close()But internally the socket is a non blocking green socket. The async client also offers async methods that receive continuation functions that will be called when the operation returns success or an error occurs.
import kinetic
c = kinetic.AsyncClient('localhost', 8123)
def on_success(m): print m
def on_error(ex): print ex
c.connect()
c.putAsync(on_success, on_error, 'my_key', 'my_value')
c.getAsync(on_success, on_error, 'my_key')
c.flush() # wait until all responses are received
c.close() # then close the clientOn the previous example, although the operations are added to an internal queue and sent in order, there is no guarantee they will arrive to the drive in the same order. The previous example can be changed to make sure the get is sent after the put in the follow way.
import kinetic
c = kinetic.AsyncClient('localhost', 8123)
def on_success(m): print m
def on_put_success(m):
c.getAsync(on_success, on_error, 'my_key')
def on_error(ex): print ex
c.connect()
c.putAsync(on_put_success, on_error, 'my_key', 'my_value')
c.flush() # wait until all responses are received
c.close() # then close the clientGot back to Clients