Skip to content
This repository has been archived by the owner on Jul 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #4 from sprockets/allow-different-ports
Browse files Browse the repository at this point in the history
Allow different ports to be used
  • Loading branch information
chrismcguire committed Jun 1, 2015
2 parents 0f6b76b + 3283d2f commit 752d489
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions sprockets/clients/cassandra/__init__.py
Expand Up @@ -20,7 +20,8 @@
version_info = (0, 0, 1)
__version__ = '.'.join(str(v) for v in version_info)

DEFAULT_URI = 'cassandra://localhost'
DEFAULT_URI = 'cassandra://localhost:9042'
DEFAULT_PORT = 9042


class CassandraConnection(object):
Expand Down Expand Up @@ -48,13 +49,13 @@ class CassandraConnection(object):

def __init__(self, ioloop=None):
self._config = self._get_cassandra_config()
self._cluster = Cluster(self._config['contact_points'])
self._cluster = Cluster(contact_points=self._config['contact_points'],
port=self._config['port'])
self._session = self._cluster.connect()
self._ioloop = IOLoop.current()

def _get_cassandra_config(self):
"""Retrieve a dict containing Cassandra client config params."""
config = {}
parts = urlsplit(os.environ.get('CASSANDRA_URI', DEFAULT_URI))
if parts.scheme != 'cassandra':
raise RuntimeError(
Expand All @@ -64,8 +65,10 @@ def _get_cassandra_config(self):
if not ip_addresses:
raise RuntimeError('Unable to find Cassandra in DNS!')

config['contact_points'] = ip_addresses
return config
return {
'contact_points': ip_addresses,
'port': parts.port or DEFAULT_PORT,
}

def set_keyspace(self, keyspace):
"""Set the keyspace used by the connection."""
Expand Down

0 comments on commit 752d489

Please sign in to comment.