2017 © Pedro Peláez
 

symfony-bundle cassandra-bundle

Symfony2 bundle on top of datastax/php-driver

image

m6web/cassandra-bundle

Symfony2 bundle on top of datastax/php-driver

  • Thursday, May 31, 2018
  • by M6Web
  • Repository
  • 24 Watchers
  • 27 Stars
  • 76,004 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 20 Forks
  • 1 Open issues
  • 21 Versions
  • 8 % Grown

The README.md

CassandraBundle

Build Status, (*1)

The CassandraBundle provide a Cassandra client as a Symfony service., (*2)

Installation

NOTE : You need to install the offical datastax php driver extension, (*3)

Use composer:, (*4)

composer require m6web/cassandra-bundle

Then make sure the bundle is registered in your application:, (*5)

// config/bundles.php

return [
    \M6Web\Bundle\CassandraBundle\M6WebCassandraBundle::class => ['all' => true],
];

Usage

Add the m6web_cassandra section in your configuration file. Here is the minimal configuration required., (*6)

m6web_cassandra:
    clients:
        myclient:
            contact_endpoints:
                - 127.0.0.1
                - 127.0.0.2
                - 127.0.0.3

Then you can ask container for your client :, (*7)

$cassandra = $this->get('m6web_cassandra.client.myclient');

$prepared = $cassandra->prepare("INSERT INTO test (id, title) VALUES(?, ?)");

$batch     = new Cassandra\BatchStatement(Cassandra::BATCH_LOGGED);
$batch->add($prepared, ['id' => 1, 'title' => 'my title']);
$batch->add($prepared, ['id' => 2, 'title' => 'my title 2']);

$cassandra->execute($batch);

$statement = new Cassandra\SimpleStatement('SELECT * FROM test');
$result = $cassandra->execute($statement);

foreach ($result as $row) {
    // do something with $row
}

$statement = new Cassandra\SimpleStatement('SELECT * FROM test');
$result = $cassandra->executeAsync($statement);

// do something while cassandra query running

foreach($result->get() as $row) {
    // do something with row
}

Bundle provide a util class for extracting Datetime from a timeuuid string., (*8)

use M6Web\Bundle\CassandraBundle\Cassandra\Type as TypeUtils;

$datetime = TypeUtils::getDateTimeFromTimeuuidString('513a5340-6da0-11e5-815e-93ec150e89fd');

if (is_null($datetime)) {
    // something is wrong with supplied uuid
} else {
    echo $datetime->format(\DateTime::W3C); // 2015-10-08 11:38:22+02:00
}

DataCollector

Datacollector is available when the symfony profiler is enabled. The collector allows you to see the following Cassandra data :, (*9)

  • keyspace
  • command name
  • command arguments
  • execution time
  • execution options override (consistency, serial consistency, page size and timeout)

NOTE : The time reported in the data collector may not be the real execution time in case you use the async calls : executeAsync and prepareAsync, (*10)

Configuration reference

m6web_cassandra:
    dispatch_events: true                 # By default event are triggered on each cassandra command
    clients:
        client_name:
            persistent_sessions: true     # persistent session connection 
            keyspace: "mykeyspace"        # default is null, optional keyspace to connect
            load_balancing: "round-robin" # round-robin or dc-aware-round-robin
            dc_options:                   # required if load balancing is set to dc-aware-round-robin
                local_dc_name: "testdc"
                host_per_remote_dc: 3
                remote_dc_for_local_consistency: false
            default_consistency: "one"    # 'one', 'any', 'two', 'three', 'quorum', 'all', 'local_quorum', 'each_quorum', 'serial', 'local_serial', 'local_one'
            default_pagesize: 10000       # ~ to disable pagination
            contact_endpoints:            # required list of ip to contact
                - 127.0.0.1
            contact_whitelist:            # if specified cassandra will connect only to this datacenters/hosts
                dc:
                    - "testdc"
                host:
                    - 172.0.0.1
            contact_blacklist:            # if specified cassandra will not connect to this datacenters/hosts
                dc:
                    - "blacklisted_testdc"
                host:
                    - 6.6.6.6
            port_endpoint: 9042           # cassandra port
            token_aware_routing: true     # Enable or disable token aware routing
            credentials:                  # cassandra authentication
                username: ""              # username for authentication
                password: ""              # password for authentication
            ssl: false                    # set up ssl context
            default_timeout: null         # default is null, must be an integer if set
            timeout:
                connect: 5 
                request: 5 
            retries:
                sync_requests: 0          # Number of retries for synchronous requests. Default is 0, must be an integer if set

        client_name:
            ...

Contributing

First of all, thank you for contributing !, (*11)

Here are few rules to follow for a easier code review before the maintainers accept and merge your request., (*12)

  • you MUST follow the Symfony2 coding standard : you can use ./bin/coke to validate
  • you MUST run the test
  • you MUST write or update tests
  • you MUST write or update documentation

Running the test

Install the composer dev dependencies, (*13)

$ composer install --dev

Then run the test with atoum unit test framework, (*14)

./bin/atoum

The Versions

31/05 2018

dev-master

9999999-dev

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-cassandra ^1.3.0

 

The Development Requires

bundle cassandra

31/05 2018
30/05 2018
08/01 2018
31/12 2017

dev-fix/compat-sf4

dev-fix/compat-sf4

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-cassandra ^1.3.0

 

The Development Requires

bundle cassandra

31/07 2017
24/04 2017
06/04 2017
31/03 2017

dev-fix/compatible-driver-1.3.0

dev-fix/compatible-driver-1.3.0

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-cassandra 1.3.0

 

The Development Requires

bundle cassandra

27/02 2017
16/11 2016
15/11 2016
07/09 2016
17/02 2016
09/02 2016
21/10 2015
21/10 2015

v1.0.0-rc

1.0.0.0-RC

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-cassandra *

 

The Development Requires

bundle cassandra

08/09 2015

v1.0.0-beta.2

1.0.0.0-beta2

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-cassandra *

 

The Development Requires

bundle cassandra

08/06 2015

v1.0.0-beta.1

1.0.0.0-beta1

Symfony2 bundle on top of datastax/php-driver

  Sources   Download

MIT

The Requires

  • php >=5.5
  • ext-cassandra *

 

The Development Requires

bundle cassandra

25/05 2015