Skip to content

Instantly share code, notes, and snippets.

@mgwilliams
Created September 20, 2011 17:54

Revisions

  1. mgwilliams revised this gist Sep 20, 2011. 1 changed file with 26 additions and 9 deletions.
    35 changes: 26 additions & 9 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,27 @@
    from twisted.application.internet import TCPClient
    from telephus.protocol import ManagedCassandraClientFactory
    from telephus.client import CassandraClient
    @defer.inlineCallbacks
    def setUp(self):
    self.cmanager = ManagedCassandraClientFactory(keyspace='system')
    self.client = CassandraClient(self.cmanager)
    for i in xrange(CONNS):
    reactor.connectTCP(HOST, PORT, self.cmanager)
    yield self.cmanager.deferred

    self.my_keyspace = KsDef(
    name=KEYSPACE,
    strategy_class='org.apache.cassandra.locator.SimpleStrategy',
    replication_factor=1,
    cf_defs=[
    CfDef(
    keyspace=KEYSPACE,
    name=CF,
    column_type='Standard'
    ),
    ]
    )
    try:
    yield self.client.system_drop_keyspace(self.my_keyspace.name)
    except:
    pass

    class Service(TCPClient):

    def __init__(self, keyspace=None, host="localhost", port=9160, delegate=None):
    f = ManagedCassandraClientFactory(keyspace)
    delegate.set_client(CassandraClient(f))
    TCPClient.__init__(self, host, port, f)
    yield self.client.system_add_keyspace(self.my_keyspace)
    yield self.client.set_keyspace(KEYSPACE)
  2. mgwilliams created this gist Sep 20, 2011.
    10 changes: 10 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    from twisted.application.internet import TCPClient
    from telephus.protocol import ManagedCassandraClientFactory
    from telephus.client import CassandraClient

    class Service(TCPClient):

    def __init__(self, keyspace=None, host="localhost", port=9160, delegate=None):
    f = ManagedCassandraClientFactory(keyspace)
    delegate.set_client(CassandraClient(f))
    TCPClient.__init__(self, host, port, f)