예제 #1
0
def xdb_get(k):
    peer2peer.publish(XDb, "dbd", "%s get 53 %s" % (UUID, k))
    return _xdb_ret()
예제 #2
0
def db_keys(k):
    #print("DBK:"+k)
    peer2peer.publish(Db, "dbd", "%s keys 51k %s %s~" % (UUID, k, k))
    return _db_ret()
예제 #3
0
def xdb_keys(k):
    peer2peer.publish(XDb, "dbd", "%s keys 51 %s %s~" % (UUID, k, k))
    return _xdb_ret()
예제 #4
0
def xdb_put(k, v):
    peer2peer.publish(XDb, "dbd", "%s put 52 %s %s" % (UUID, k, v))
    return _xdb_ret()
예제 #5
0
def publish(ch, msg):
    return peer2peer.publish(Ps, ch, msg)
예제 #6
0
def xpublish(ch, msg):
    return peer2peer.publish(Xps, ch, msg)
예제 #7
0
def db_get(k):
    #print("DBG:"+k)
    peer2peer.publish(Db, "dbd", "%s get 53g %s" % (UUID, k))
    return _db_ret()
예제 #8
0
def db_put(k, v):
    #print("DBP:"+k)
    peer2peer.publish(Db, "dbd", "%s put 52p %s %s" % (UUID, k, v))
    return _db_ret()
예제 #9
0
def main():
    while 1:
        try:
            peer2peer.subscribe(Ps, 'dbd')
            while 1:
                msgs = peer2peer.recv(Ps)
                msg = msgs[2]
                arr = msg.split(' ', 4)
                if   arr[1] == 'hola':
                    peer2peer.publish(Ps, arr[0], arr[2] + " YO!")
                elif arr[1] == 'put':
                    db.Put(arr[3], arr[4])
                    peer2peer.publish(Ps, arr[0], arr[2] + " OK")
                elif arr[1] == 'get':
                    try:
                        result = db.Get(arr[3])
                        peer2peer.publish(Ps, arr[0], arr[2] + ' ' + result)
                    except KeyError:
                        peer2peer.publish(Ps, arr[0], arr[2])
                elif arr[1] == 'keys':
                    try:
                        result = ' '.join(list(keys(arr[3],arr[4])))
                        #print("RESLT", repr(result))
                        peer2peer.publish(Ps, arr[0], arr[2] + ' ' + result)
                    except KeyError:
                        peer2peer.publish(Ps, arr[0], arr[2])
                elif arr[1] == 'zap':
                    for key in keys(''):
                        db.Delete(key)
                else:
                    print("ERROR, DONT KNOW HOW TO DO THAT")
                    pass
                time.sleep(0.2)
        except:
            tb.print_exc()
            print("ERR")
            time.sleep(1)
            try:
                connect()
            except:
                print("ERR2")
                tb.print_exc()
                pass
            pass