Cassandra\Cluster builder allows fluent configuration of the cluster instance.

See Also:

Methods

Cassandra\Cluster

build

( )

Returns a Cassandra\Cluster Instance.

Returns:
Type Details
Cassandra\Cluster

Cassandra\Cluster instance

Cluster\Builder

withDefaultConsistency

( int $consistency )

Configures default consistency for all requests.

Parameters:
Name Type Details
$consistency int

A consistency level, must be one of Cassandra::CONSISTENCY_* values

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDefaultPageSize

( int $pageSize )

Configures default page size for all results. Cassandra\Set to null to disable paging altogether.

Parameters:
Name Type Details
$pageSize int

default page size

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDefaultTimeout

( float $timeout )

Configures default timeout for future resolution in blocking operations Cassandra\Set to null to disable (default).

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withContactPoints

( string $host )

Configures the initial endpoints. Note that the driver will automatically discover and connect to the rest of the cluster.

Parameters:
Name Type Details
$host string

one or more ip addresses or hostnames

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withPort

( int $port )

Specify a different port to be used when connecting to the cluster.

Parameters:
Name Type Details
$port int

a number between 1 and 65535

Throws:
Type Details
Exception\InvalidArgumentException
Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withRoundRobinLoadBalancingPolicy

( )

Configures this cluster to use a round robin load balancing policy.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withDatacenterAwareRoundRobinLoadBalancingPolicy

( string $localDatacenter, int $hostPerRemoteDatacenter, bool $useRemoteDatacenterForLocalConsistencies )

Configures this cluster to use a datacenter aware round robin load balancing policy.

Parameters:
Name Type Details
$localDatacenter string

Name of the local datacenter

$hostPerRemoteDatacenter int

Maximum number of hosts to try in remote datacenters

$useRemoteDatacenterForLocalConsistencies bool

Allow using hosts from remote datacenters to execute statements with local consistencies

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTokenAwareRouting

( bool $enabled = true )

Enable token aware routing.

Parameters:
Name Type Details
$enabled bool

Whether to enable token aware routing (optional)

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withCredentials

( string $username, string $password )

Configures cassandra authentication.

Parameters:
Name Type Details
$username string

Username

$password string

Password

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withConnectTimeout

( float $timeout )

Timeout used for establishing TCP connections.

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withRequestTimeout

( float $timeout )

Timeout used for waiting for a response from a node.

Parameters:
Name Type Details
$timeout float

Timeout value in seconds, can be fractional

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withSSL

( Cassandra\SSLOptions $options )

Cassandra\Set up ssl context.

Parameters:
Name Type Details
$options Cassandra\SSLOptions

a preconfigured ssl context

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withPersistentSessions

( bool $enabled = true )

Enable persistent sessions and clusters.

Parameters:
Name Type Details
$enabled bool

whether to enable persistent sessions and clusters (optional)

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withProtocolVersion

( int $version )

Force the driver to use a specific binary protocol version.

  • Apache Cassandra 1.2+ supports protocol version 1
  • Apache Cassandra 2.0+ supports protocol version 2
Parameters:
Name Type Details
$version int

the actual protocol version, only 1 or 2 are supported

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withIOThreads

( int $count )

Total number of IO threads to use for handling the requests.

Note: number of io threads * core connections per host <= total number of connections <= number of io threads * max connections per host

Parameters:
Name Type Details
$count int

total number of threads.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withConnectionsPerHost

( int $core = 1, int $max = 2 )

Cassandra\Set the size of connection pools used by the driver. Pools are fixed when only $core is given, when a $max is specified as well, additional connections will be created automatically based on current load until the maximum number of connection has been reached. When request load goes down, extra connections are automatically cleaned up until only the core number of connections is left.

Parameters:
Name Type Details
$core int

minimum connections to keep open to any given host

$max int

maximum connections to keep open to any given host

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withReconnectInterval

( float $interval )

Specify interval in seconds that the driver should wait before attempting to re-establish a closed connection.

Parameters:
Name Type Details
$interval float

interval in seconds

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withLatencyAwareRouting

( bool $enabled = true )

Enables/disables latency-aware routing.

Parameters:
Name Type Details
$enabled bool

whether to actually enable or disable the routing.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTCPNodelay

( bool $enabled = true )

Disables nagle algorithm for lower latency.

Parameters:
Name Type Details
$enabled bool

whether to actually enable or disable nodelay.

Returns:
Type Details
Cluster\Builder

self

Cluster\Builder

withTCPKeepalive

( float $delay )

Enables/disables TCP keepalive.

Parameters:
Name Type Details
$delay float

the period of inactivity in seconds, after which the keepalive probe should be sent over the connection. If set to null, disables keepalive probing.

Returns:
Type Details
Cluster\Builder

self