clients.cassandra

Base functionality for accessing/modifying data in Cassandra.

class sprockets.clients.cassandra.CassandraConnection(ioloop=None)[source]

Maintain a connection to a Cassandra cluster.

The Sprockets Cassandra client handles provides the glue needed to join the Tornado async I/O module with the native python async I/O used in the Cassandra driver. The constructor of the function will grab the current handle to the underlying Tornado I/O loop so that a Tornado future result can be returned to the host application.

Configuration parameters for the module are obtained from environment variables. Currently, the only variable is CASSANDRA_URI, which takes the format “cassandra://hostname”. If not located, the hostname defaults to localhost.

Note

The hostname in the CASSANDRA_URI will be resolved to a list of IP addresses that will be passed to the Cassandra driver as the contact points.

execute(query, *args, **kwargs)[source]

Asynchronously execute the specified CQL query.

The execute command also takes optional parameters and trace keyword arguments. See cassandra-python documentation for definition of those parameters.

prepare(query, name=None)[source]

Create and cache a prepared statement using the provided query.

This function will take a query and optional name parameter and will create a new prepared statement for the provided query. The resulting statement object will be cached so future invocations of this function will not incur the overhead or recreating the statement. If name is provided it will be used as the key for the cache, so you’ll be able to call execute using the name.

Pram str query:The query to prepare.
Pram str name:(Optional) name to use as a key in the cache.
set_keyspace(keyspace)[source]

Set the keyspace used by the connection.

shutdown()[source]

Shutdown the connection to the Cassandra cluster.