Skip to content

Commit

Permalink
Merge remote-tracking branch 'driftx/master' into sasl-support
Browse files Browse the repository at this point in the history
Conflicts:
	telephus/pool.py
	telephus/protocol.py
  • Loading branch information
thobbs committed Feb 1, 2013
2 parents 1809361 + e00cd62 commit e006cae
Show file tree
Hide file tree
Showing 19 changed files with 2,508 additions and 545 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*.pyc
*.sw?
*.cache
_trial_temp
21 changes: 0 additions & 21 deletions README

This file was deleted.

30 changes: 30 additions & 0 deletions README.rst
@@ -0,0 +1,30 @@
Telephus
========
Son of Heracles who loved Cassandra. He went a little crazy, at one point. One
might almost say he was twisted.

Description
-----------
Telephus is a connection pooled, low-level client API for Cassandra in Twisted
(Python).


Installation
------------
Prerequisites:

* Python >= 2.4 (2.5 or later for tests)
* Twisted 8.1.0 or later
* Thrift (latest svn)


Usage
-----
See example.py for an example of how to use the Telephus API.


Unit Tests
----------
To run the unit tests, simply use the Twisted test runner, ``trial``::

$ trial test/
Empty file added examples/deferreds/basic.py
Empty file.
Empty file added examples/deferreds/column.py
Empty file.
Empty file.
Empty file added examples/deferreds/keyspace.py
Empty file.
Empty file added examples/deferreds/sorting.py
Empty file.
Empty file.
Empty file.
49 changes: 32 additions & 17 deletions example.py → examples/inlinecallbacks/basic.py
@@ -1,9 +1,12 @@
#!/usr/bin/python
from telephus.protocol import ManagedCassandraClientFactory
from telephus.client import CassandraClient
from telephus.cassandra.ttypes import ColumnPath, ColumnParent, Column, SuperColumn
from twisted.internet import defer

from telephus.cassandra.ttypes import (
ColumnPath, ColumnParent, Column, SuperColumn)
from telephus.client import CassandraClient
from telephus.protocol import ManagedCassandraClientFactory


HOST = 'localhost'
PORT = 9160
KEYSPACE = 'Keyspace1'
Expand All @@ -14,21 +17,27 @@
colname = 'foo'
scname = 'bar'


@defer.inlineCallbacks
def dostuff(client):
yield client.insert(key='test', column_family=CF, value='testval', column=colname)
yield client.insert(key='test', column_family=SCF, value='testval', column=colname, super_column=scname)
yield client.insert(
key='test', column_family=CF, value='testval', column=colname)
yield client.insert(
key='test', column_family=SCF, value='testval', column=colname,
super_column=scname)

res = yield client.get(key='test', column_family=CF, column=colname)
print 'get', res

res = yield client.get(key='test', column_family=SCF, column=colname, super_column=scname)
res = yield client.get(
key='test', column_family=SCF, column=colname, super_column=scname)
print 'get (super)', res

res = yield client.get_slice(key='test', column_family=CF)
print 'get_slice', res

res = yield client.multiget(keys=['test', 'test2'], column_family=CF, column=colname)
res = yield client.multiget(
keys=['test', 'test2'], column_family=CF, column=colname)
print 'multiget', res

res = yield client.multiget_slice(keys=['test', 'test2'], column_family=CF)
Expand All @@ -37,21 +46,27 @@ def dostuff(client):
res = yield client.get_count(key='test', column_family=CF)
print 'get_count', res

yield client.add(key='test', column_family=COUNT_CF, value=1, column='testcounter')
res = yield client.get(key='test', column_family=COUNT_CF, column='testcounter')
yield client.add(
key='test', column_family=COUNT_CF, value=1, column='testcounter')
res = yield client.get(
key='test', column_family=COUNT_CF, column='testcounter')
print 'get counter value', res

yield client.add(key='test', column_family=SUPERCOUNT_CF, value=1,
column='testcounter', super_column='testsuper')
res = yield client.get(key='test', column_family=SUPERCOUNT_CF,
column='testcounter', super_column='testsuper')
yield client.add(
key='test', column_family=SUPERCOUNT_CF, value=1, column='testcounter',
super_column='testsuper')
res = yield client.get(
key='test', column_family=SUPERCOUNT_CF, column='testcounter',
super_column='testsuper')
print 'get super counter value', res

# batch insert will figure out if you're trying a CF or SCF
# from the data structure
res = yield client.batch_insert(key='test', column_family=CF, mapping={colname: 'bar'})
res = yield client.batch_insert(
key='test', column_family=CF, mapping={colname: 'bar'})
print "batch_insert", res
res = yield client.batch_insert(key='test', column_family=SCF, mapping={'foo': {colname: 'bar'}})
res = yield client.batch_insert(
key='test', column_family=SCF, mapping={'foo': {colname: 'bar'}})
print "batch_insert", res

# with ttypes, you pass a list as you would for raw thrift
Expand All @@ -68,11 +83,11 @@ def dostuff(client):


if __name__ == '__main__':
import sys
from twisted.internet import reactor
from twisted.python import log
import sys
log.startLogging(sys.stdout)

log.startLogging(sys.stdout)
f = ManagedCassandraClientFactory(KEYSPACE)
c = CassandraClient(f)
dostuff(c)
Expand Down
10 changes: 7 additions & 3 deletions setup.py
@@ -1,14 +1,18 @@
#!/usr/bin/python

from distutils.core import setup


setup(
name='telephus',
version='1.0.0_beta1',
description='connection pooled, low-level client API for Cassandra in Twisted python',
version='1.0.0~beta1',
description=('connection pooled, low-level client API for Cassandra in '
'Twisted (Python)'),
author='brandon@faltering.com',
url='http://github.com/driftx/Telephus',
packages=['telephus',
'telephus.cassandra',
'telephus.cassandra.c07',
'telephus.cassandra.c08']
'telephus.cassandra.c08',
'telephus.test']
)

0 comments on commit e006cae

Please sign in to comment.