CassandraManager¶
The CassandraManager
manages all the interactions with Cassandra.
Import¶
from primeight import CassandraManager
Constructor¶
- contact_points
List[str]
[Required]: List of Cassandra contact points. - connect_timeout
float
(Default:5.0
): Timeout, in seconds, for creating new connections. - control_connection_timeout
float
(Default:2.0
): A timeout, in seconds, for queries made by the control connection, such as querying the current schema and information about nodes in the cluster. If set toNone
, there will be no timeout for these queries. - profiles
Dict[str, cassandra.cluster.ExecutionProfile]
(Default:None
): Dictionary of Cassandra Execution Profiles, with the execution profile name as key. These profiles are available when executing queries. If set toNone
, defaults to a execution profile with:cassandra.policies.RoundRobinPolicy
load balancing policycassandra.policies.RetryPolicy
retry policyLOCAL_ONE
consistency levelcassandra.query.dict_factory
row factory10.0
secondrequest_timeout
Attributes¶
contact_points¶
Type: List[str]
List of Cassandra contact points, i.e. the addresses used to connect.
cluster¶
Type: cassandra.cluster.Cluster
Cassandra Cluster object.
session¶
Type: cassandra.cluster.Session
Cassandra Session object.
execution_profiles¶
Type: Dict[str, cassandra.cluster.ExecutionProfile]
Dictionary of Cassandra ExecutionProfiles,
with the execution profile name as key.
These profiles are available when executing queries.
address_translator¶
Type: cassandra.policies.AddressTranslator
Cassandra AddressTranslator in use (if any).
Methods¶
create_execution_profile¶
Static Method
Create a Cassandra execution profile.
Parameters:
- load_balancing_policy
cassandra.policies.LoadBalancingPolicy
[Required] - retry_policy
cassandra.policies.RetryPolicy
[Required] - consistency_level
cassandra.policies.RetryPolicy
(Default:cassandra.ConsistencyLevel.LOCAL_ONE
) - row_factory
Callable
(Default:cassandra.query.dict_factory
) - request_timeout
float
(Default:10.0
)
Return: cassandra.cluster.ExecutionProfile
connect¶
Connect to Cassandra, and creates a session.
Parameters:
- keyspace
str
(Default:None
): Default keyspace for operations.
Return: self
execute¶
Execute statement(s) sequentially.
The return type depends on the row_factory
defined in the execution profile.
Parameters:
- statements
List[str]
(Default:None
): List of statements - execution_profile
str or cassandra.cluster.ExecutionProfile
(Default:None
): Execution profile name or ExecutionProfile object
Return: List[tuple] or List[dict]
execute_concurrent¶
Execute statement(s) concurrently.
The return type depends on the row_factory
defined in the execution profile.
Parameters:
- statements
List[str]
(Default:None
): List of statements - raise_on_first_error
bool
(Default:False
): Whether to stop after the first failed statement
Return: List[tuple] or List[dict]