Menu

CassSession

struct CassSession

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.

Public Functions

CassSession *cass_session_new()

Creates a new session.

Return

Returns a session that must be freed.

See

cass_session_free()

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
  • session:

CassFuture *cass_session_connect(CassSession *session, const CassCluster *cluster)

Connects a session.

Return

A future that must be freed.

See

cass_session_close()

Parameters
  • session:

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

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

Connects a session and sets the keyspace.

Return

A future that must be freed.

See

cass_session_close()

Parameters
  • session:

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

  • keyspace:

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

Same as cass_session_connect_keyspace(), but with lengths for string parameters.

Return

same as cass_session_connect_keyspace()

See

cass_session_connect_keyspace()

Parameters
  • session:

  • cluster:

  • keyspace:

  • keyspace_length:

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.

Return

A future that must be freed.

Parameters
  • session:

CassFuture *cass_session_prepare(CassSession *session, const char *query)

Create a prepared statement.

Return

A future that must be freed.

See

cass_future_get_prepared()

Parameters
  • session:

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

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

Same as cass_session_prepare(), but with lengths for string parameters.

Return

same as cass_session_prepare()

See

cass_session_prepare()

Parameters
  • session:

  • query:

  • query_length:

CassFuture *cass_session_prepare_from_existing(CassSession *session, CassStatement *statement)

Create a prepared statement from an existing statement.

Note: Bound statements will inherit the keyspace, consistency, serial consistency, request timeout and retry policy of the existing statement.

Return

A future that must be freed.

See

cass_future_get_prepared()

Parameters
  • session:

  • statement:

CassFuture *cass_session_execute(CassSession *session, const CassStatement *statement)

Execute a query or bound statement.

Return

A future that must be freed.

See

cass_future_get_result()

Parameters
  • session:

  • statement:

CassFuture *cass_session_execute_batch(CassSession *session, const CassBatch *batch)

Execute a batch statement.

Requires Apache Cassandra: 2.0+

Return

A future that must be freed.

See

cass_future_get_result()

Parameters
  • session:

  • batch:

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.

Return

A schema instance that must be freed.

See

cass_schema_meta_free()

Parameters
  • session:

void cass_session_get_metrics(const CassSession *session, CassMetrics *output)

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

Parameters
  • session:

  • output:

void cass_session_get_speculative_execution_metrics(const CassSession *session, CassSpeculativeExecutionMetrics *output)

Gets a copy of this session’s speculative execution metrics.

Parameters
  • session:

  • output:

CassUuid cass_session_get_client_id(CassSession *session)

Get the client id.

Return

Client id.

Parameters
  • session: