Skip to content

Instantly share code, notes, and snippets.

@clofresh
Created August 15, 2009 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clofresh/168357 to your computer and use it in GitHub Desktop.
Save clofresh/168357 to your computer and use it in GitHub Desktop.
#!/bin/bash
HOST=127.0.0.1
PORT=1978
SID=1
UPDATE_LOG_DIR=ulog/$SID
MASTER_HOST=127.0.0.1
MASTER_PORT=1979
mkdir -p $UPDATE_LOG_DIR
ttserver -host $HOST \
-port $PORT \
-ulog $UPDATE_LOG_DIR \
-sid $SID \
-mhost $MASTER_HOST \
-mport $MASTER_PORT
#!/bin/bash
HOST=127.0.0.1
PORT=1979
SID=2
UPDATE_LOG_DIR=ulog/$SID
MASTER_HOST=127.0.0.1
MASTER_PORT=1978
mkdir -p $UPDATE_LOG_DIR
ttserver -host $HOST \
-port $PORT \
-ulog $UPDATE_LOG_DIR \
-sid $SID \
-mhost $MASTER_HOST \
-mport $MASTER_PORT
import pytyrant
import time
t1 = pytyrant.PyTyrant.open('127.0.0.1', 1978)
t2 = pytyrant.PyTyrant.open('127.0.0.1', 1979)
print t2.get('foo', 'nothing here') # 'nothing here'
# Writing to t1 replicates to t2
t1['foo'] = 'bar'
print t2.get('foo', 'nothing here') # 'foo'
# Tokyo Tyrant also speaks the memcached protocol
import memcache
mc = memcache.Client(['127.0.0.1:1978', '127.0.0.1:1979'])
print mc.get('foo') # 'bar'
mc.set('yo', 'sup') # Assigns ('yo', 'sup') pair to one of the servers in the pool
# Both Tyrant servers should have ('yo', 'sup') because of master-master replication
print t1.get('yo', 'nothing in t1') # 'sup'
print t2.get('yo', 'nothing in t2') # 'sup'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment