David Reiss | 9f3296b | 2010-08-31 16:58:41 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | import sys |
| 3 | import time |
| 4 | import zmq |
| 5 | import TZmqClient |
| 6 | import thrift.protocol.TBinaryProtocol |
| 7 | import storage.ttypes |
| 8 | import storage.Storage |
| 9 | |
| 10 | |
| 11 | def main(args): |
| 12 | endpoint = "tcp://127.0.0.1:9090" |
| 13 | socktype = zmq.REQ |
| 14 | incr = 0 |
| 15 | if len(args) > 1: |
| 16 | incr = int(args[1]) |
| 17 | if incr: |
| 18 | socktype = zmq.DOWNSTREAM |
| 19 | endpoint = "tcp://127.0.0.1:9091" |
| 20 | |
| 21 | ctx = zmq.Context() |
| 22 | transport = TZmqClient.TZmqClient(ctx, endpoint, socktype) |
| 23 | protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocolAccelerated(transport) |
| 24 | client = storage.Storage.Client(protocol) |
| 25 | transport.open() |
| 26 | |
| 27 | if incr: |
| 28 | client.incr(incr) |
| 29 | time.sleep(0.05) |
| 30 | else: |
| 31 | value = client.get() |
| 32 | print value |
| 33 | |
| 34 | |
| 35 | if __name__ == "__main__": |
| 36 | main(sys.argv) |