Book Image

Apache Cassandra Essentials

By : Nitin Padalia
Book Image

Apache Cassandra Essentials

By: Nitin Padalia

Overview of this book

Apache Cassandra Essentials takes you step-by-step from from the basics of installation to advanced installation options and database design techniques. It gives you all the information you need to effectively design a well distributed and high performance database. You’ll get to know about the steps that are performed by a Cassandra node when you execute a read/write query, which is essential to properly maintain of a Cassandra cluster and to debug any issues. Next, you’ll discover how to integrate a Cassandra driver in your applications and perform read/write operations. Finally, you’ll learn about the various tools provided by Cassandra for serviceability aspects such as logging, metrics, backup, and recovery.
Table of Contents (14 chapters)
Apache Cassandra Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Create keyspace and column family


Now, let's create our keyspace and a column family using the cqlsh client. Run the command cqlsh, then you should be on the cqlsh prompt. On the cqlsh prompt, run the keyspace creation command as follows:

cqlsh> CREATE KEYSPACE cassandrademodb WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };

Here, we created a keyspace named cassandrademodb. We chose the replication factor as 3, so each data row we'll be creating will be stored on three nodes. Since, for now we're running our cluster on only one cluster, we chose the replication strategy as SimpleStrategy.

Now, create one column family called users in this keyspace. Here, we'll use username column as the partition key. Using the cqlsh prompt we can create it as follows:

cqlsh> use cassandrademodb;
cqlsh:cassandrademodb> CREATE TABLE songs ( username text PRIMARY KEY, email text, address text );

Here, we defined the username as a partition key as well as a primary key. However...