A session object is used to execute queries and maintains cluster state through the control connection. The control connection is used to auto-discover nodes and monitor cluster changes (topology and schema). Each session also maintains multiple pools of connections to cluster nodes which are used to query the cluster.

Instances of the session object are thread-safe to execute queries.

Functions

CassSession *

cass_session_new

( )

Creates a new session.

Returns:
Type Details
CassSession *

Returns a session that must be freed.

See Also:
void

cass_session_free

( CassSession * session )

Frees a session instance. If the session is still connected it will be synchronously closed before being deallocated.

Important: Do not free a session in a future callback. Freeing a session in a future callback will cause a deadlock.

Parameters:
Name Type Details
in session CassSession *
CassFuture *

cass_session_connect

( CassSession * session, const CassCluster * cluster )

Connects a session.

Parameters:
Name Type Details
in session CassSession *
in cluster const CassCluster *

The cluster configuration is copied into the session and is immutable after connection.

Returns:
Type Details
CassFuture *

A future that must be freed.

See Also:
CassFuture *

cass_session_connect_keyspace

( CassSession * session, const CassCluster * cluster, const char * keyspace )

Connects a session and sets the keyspace.

Parameters:
Name Type Details
in session CassSession *
in cluster const CassCluster *

The cluster configuration is copied into the session and is immutable after connection.

in keyspace const char *
Returns:
Type Details
CassFuture *

A future that must be freed.

See Also:
CassFuture *

cass_session_connect_keyspace_n

( CassSession * session, const CassCluster * cluster, const char * keyspace, size_t keyspace_length )

Same as CassSession::cass_session_connect_keyspace, but with lengths for string parameters.

Parameters:
Name Type Details
in session CassSession *
in cluster const CassCluster *
in keyspace const char *
in keyspace_length size_t
Returns:
Type Details
CassFuture *

same as CassSession::cass_session_connect_keyspace

See Also:
CassFuture *

cass_session_close

( CassSession * session )

Closes the session instance, outputs a close future which can be used to determine when the session has been terminated. This allows in-flight requests to finish.

Parameters:
Name Type Details
in session CassSession *
Returns:
Type Details
CassFuture *

A future that must be freed.

CassFuture *

cass_session_prepare

( CassSession * session, const char * query )

Create a prepared statement.

Parameters:
Name Type Details
in session CassSession *
in query const char *

The query is copied into the statement object; the memory pointed to by this parameter can be freed after this call.

Returns:
Type Details
CassFuture *

A future that must be freed.

See Also:
CassFuture *

cass_session_prepare_n

( CassSession * session, const char * query, size_t query_length )

Same as CassSession::cass_session_prepare, but with lengths for string parameters.

Parameters:
Name Type Details
in session CassSession *
in query const char *
in query_length size_t
Returns:
Type Details
CassFuture *

same as CassSession::cass_session_prepare

See Also:
CassFuture *

cass_session_execute

( CassSession * session, const CassStatement * statement )

Execute a query or bound statement.

Parameters:
Name Type Details
in session CassSession *
in statement const CassStatement *
Returns:
Type Details
CassFuture *

A future that must be freed.

See Also:
CassFuture *

cass_session_execute_batch

( CassSession * session, const CassBatch * batch )

Execute a batch statement.

Requires Cassandra: 2.0+

Parameters:
Name Type Details
in session CassSession *
in batch const CassBatch *
Returns:
Type Details
CassFuture *

A future that must be freed.

See Also:
const CassSchemaMeta *

cass_session_get_schema_meta

( const CassSession * session )

Gets a snapshot of this session’s schema metadata. The returned snapshot of the schema metadata is not updated. This function must be called again to retrieve any schema changes since the previous call.

Parameters:
Name Type Details
in session const CassSession *
Returns:
Type Details
const CassSchemaMeta *

A schema instance that must be freed.

See Also:
void

cass_session_get_metrics

( const CassSession * session, CassMetrics * output )

Gets a copy of this session’s performance/diagnostic metrics.

Parameters:
Name Type Details
in session const CassSession *
out output CassMetrics *