..


Sponsored Links

Use with Cassandra PHPCassa

Article written by Ciro Cardone
Page 1 of 4

The purpose of this article is to show how to use Cassandra in our PHP applications.
Cassandra is a project within Facebook with the goal of disengaging from MySQL to store messages in the Inbox.

Cassandra belongs to the family of products nosql, namely those software solutions that store data using SQL syntax and the concept of relationship, so it is not an RDBMS, but a distributed database, designed to work in a cluster and to manage large amounts of data. Instead of using the concepts of table, tuple and relation, Cassandra uses column-oriented approach implemented through the use of Hash and Array, which stores the information in the form {key: value}.

How developed

Cassandra is now an Apache project developed java6 therefore completely portable, having only a requirement to install a JRE.

Cassandra Project

The main features of Cassandra are:

  1. Decentralization: the database is distributed on the same node within the cluster. There are bottlenecks in the network, or break points.
  2. Elasticity: the throughput for read / write increases linearly with the addition of new machines (nodes) to the cluster with no downtime or disruption to applications.
  3. Fault Tolerance: Data is automatically replicated on the nodes. It has support for the replication of multiple data centers. The failed nodes can be replaced without any downtime.
  4. "Durability" Cassandra is designed for applications where data loss is critical and should fall even when the entire data center solves the problem of data loss through a synchronization mechanism based on commitlog.
  5. Flexibility: you can choose the update for each strategy to correct the situation, replication can be synchronous or asynchronous.

To get all these benefits, however, developers have had to abandon the transaction management.

The Data Model

The columns (column) are the lowest level of organization of data in Cassandra, are tuples that contain a name, a value and a timestamp. They are often represented as an example the JSON notation:






 {



  



 "Name": "Name",



  



 "Value": "Cyrus"



  



 "Timestamp": 123456789







 }



Name and value are arrays of bytes arranged as UTF-8 strings. The key / value pair is "labels as" with a timestamp. Cassandra uses the timestamp to see what the most recent value (remember we're talking about a cluster) and then to manage conflicts.

The column column are organized into families, which are akin to a table in a relational database. A column family contains an ordered list of columns that can be referenced by their name. Each column family is saved in a separate file and the file is arranged in rows (rows).

The column families are in turn grouped into keyspaces, typically one per application. Less used are superColumns, special columns that contain within them other columns.

The typical size of 4-Cassandra is therefore as follows:

 



 Keyspace -> Column Family -> Family Row Column -> Columns -> Values

 
In the event that we add the SuperColumns:
 



 Keyspace -> Column Super Family -> Family Super Column Row -> Super Columns -> Columns -> Values

 

Here is the JSON representation of a simple notation:






 Users {



  



 "Cyrus": {



    



 "Nickname": "Ci83"



    



 "Name": "Cardone"



  



 }







 }



and a more complex uses supercolumns





 Users {



  



 "Cyrus": {



    



 "Skills": {



      



 "Java": "Great"



      



 "PHP", "Excellent"



    



 },



    



 "Registry": {



      



 "Nickname": "Ci83"



      



 "Name": "Cardone"



    



 }



  



 }







 }



In keyspace "Users" is defined as a key "Cyrus" supercolonne with two "skills" and "registry" each of which contains key / value pairs.

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links