Commit 9c54edf1 authored by Ignacio Corderi's avatar Ignacio Corderi
Browse files

Added P2P examples. Closes #12

parent 3bc422c0
Loading
Loading
Loading
Loading

examples/p2p_copy.py

0 → 100644
+20 −0
Original line number Diff line number Diff line
from kinetic import Client
import uuid

c1 = Client('localhost', 8123)
c1.connect()

key = str(uuid.uuid4())
value = str(uuid.uuid4())

print 'Writing { Key: %s, Value: %s } on first device' % (key, value)
c1.put(key,value)

print 'Copying key from first to second device'
c1.push([key], 'localhost', 8124)

c2 = Client('localhost', 8124)
c2.connect()
kv = c2.get(key)

print 'Read { Key: %s, Value: %s } from second device' % (key, value)

examples/p2p_pipe.py

0 → 100644
+31 −0
Original line number Diff line number Diff line
from kinetic import Client
from kinetic import Peer
import uuid

c1 = Client('localhost', 8123)
c1.connect()

key = str(uuid.uuid4())
value = str(uuid.uuid4())

print 'Writing { Key: %s, Value: %s } on first device' % (key, value)
c1.put(key,value)

peers = [ Peer(port=8124), Peer(port=8126)]

print 'Copying key from first to second device and telling him to copy to third'
c1.pipedPush([key], peers)

# Verify second device
c2 = Client('localhost', 8124)
c2.connect()
kv = c2.get(key)

print 'Read { Key: %s, Value: %s } from second device' % (key, value)

# Verify third device
c3 = Client('localhost', 8126)
c3.connect()
kv = c3.get(key)

print 'Read { Key: %s, Value: %s } from third device' % (key, value)
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ from threadedclient import ThreadedClient
# common
from common import KeyRange
from common import Entry
from common import Peer

# exceptions
from common import KineticMessageException