def main(reactor): # create an etcd client etcd = Client(reactor) # retrieve etcd cluster status status = yield etcd.status() print(status) # callback invoked for every change def on_change(kv): print('on_change: {}'.format(kv)) # start watching on given keys or key sets # when the key sets overlap, the callback might get called multiple # times, once for each key set matching an event keys = [KeySet(b'mykey2', b'mykey5'), KeySet(b'mykey', prefix=True)] d = etcd.watch(keys, on_change) # stop after 10 seconds print('watching for 1s ..') yield txaio.sleep(1) etcd.set(b'mykey10', b'Test') print('watching for 3s ..') yield txaio.sleep(3) d.cancel()
def main(reactor): # create an etcd client etcd = Client(reactor, u'http://localhost:2379') # retrieve etcd cluster status status = yield etcd.status() print(status)
def main(reactor): # create an etcd client etcd = Client(reactor) # retrieve etcd cluster status status = yield etcd.status() print(status)
def main(reactor): etcd = Client(reactor, u'http://localhost:2379') status = yield etcd.status() print(status) yield example1(reactor, etcd) yield example2(reactor, etcd) yield example3(reactor, etcd) yield example4(reactor, etcd) yield example5(reactor, etcd)
def main(reactor): etcd = Client(reactor) status = yield etcd.status() print(status) yield example1(reactor, etcd) yield example2(reactor, etcd) yield example3(reactor, etcd) yield example4(reactor, etcd) yield example5(reactor, etcd)
def main(reactor): etcd = Client(reactor, u'http://192.168.0.172:2379') status = yield etcd.status() print(status)
def main(reactor): if True: with TemporaryDirectory() as dbpath: print('Using temporary directory {} for database'.format(dbpath)) schema = MySchema() with zlmdb.Database(dbpath) as db: # write records into zlmdb with db.begin(write=True) as txn: for i in range(10): key = 'key{}'.format(i) value = 'value{}'.format(random.randint(0, 1000)) schema.samples[txn, key] = value # read records from zlmdb with db.begin() as txn: for i in range(10): key = 'key{}'.format(i) value = schema.samples[txn, key] print('key={} : value={}'.format(key, value)) if True: # etcd database etcd = Client(reactor) status = yield etcd.status() print(status) # zlmdb database schema = MySchema() dbpath = '/tmp/.test-zlmdb' with zlmdb.Database(dbpath) as db: print('zlmdb open on {}'.format(dbpath)) # check current record count with db.begin() as txn: cnt = schema.samples.count(txn) print('currently {} rows in table'.format(cnt)) # watch changes in etcd and write to local zlmdb def on_change(kv): key = kv.key.decode() value = kv.value.decode() with db.begin(write=True) as txn: schema.samples[txn, key] = value print( 'on_change received from etcd and written to zlmdb: key={} value={}' .format(key, value)) # start watching for etcd changes .. ks = [KeySet('k'.encode(), prefix=True)] d = etcd.watch(ks, on_change) print('watching for 1s ..') yield txaio.sleep(1) # loop every 1s and write a key-value in etcd directly for i in range(5): print('watching for 1s ..') yield txaio.sleep(1) key = 'key{}'.format(i).encode() value = 'value{}'.format(random.randint(0, 1000)).encode() etcd.set(key, value) # cancel our watch d.cancel() yield util.sleep(1) # check current record count with db.begin() as txn: cnt = schema.samples.count(txn) print('currently {} rows in table'.format(cnt)) yield util.sleep(1)