~djfroofy/+junk/tx.memcache

« back to all changes in this revision

Viewing changes to examples/simple.py

  • Committer: drew.smathers at gmail
  • Date: 2008-07-18 13:14:05 UTC
  • Revision ID: drew.smathers@gmail.com-20080718131405-dofbzm62ri0umedy
- client and hash modules + example

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2008 Drew Smathers
 
4
# See LICENSE for details. 
 
5
 
 
6
import sys
 
7
 
 
8
from twisted.internet import reactor, defer
 
9
 
 
10
from txmemcache import client
 
11
 
 
12
# USAGE
 
13
#
 
14
# python -m examples/simple.py hostx:portx[,hosty:porty,...] <command> [args]
 
15
#
 
16
# Example:
 
17
#
 
18
# python -m examples/simple.py localhost:11211,localhost:21212 set k hello
 
19
 
 
20
servers = [ (a.split(':')[0],int(a.split(':')[1]))
 
21
            for a in sys.argv[1].split(',') ]
 
22
command = sys.argv[2]
 
23
args = sys.argv[3:]
 
24
 
 
25
@defer.inlineCallbacks
 
26
def run():
 
27
    proxy = client.MultiClientProxy(servers, urlencode=True)
 
28
    yield proxy.connectTCP(timeout = 2)
 
29
    result = yield getattr(proxy, command)(*args)
 
30
    print 'Result:', result
 
31
    reactor.stop()
 
32
 
 
33
 
 
34
reactor.callLater(0.5, run)
 
35
reactor.run()
 
36