Getting up and running with Cassandra 1.0 and Ruby on OS X
I’ve been looking at the possibility of using Cassandra for an internal projects, so wanted to get a test system up and running. The latest Cassandra release at the time of writing is 1.0.6, but most of the resources I found referenced earlier versions. So here’s a quick guide to getting set up for Cassandra development with Ruby on OS X (Lion specifically, though it shouldn’t matter too much).
Download and install Cassandra
The latest tarball is linked from the project homepage. I decided to run my local install as my login user rather than root, so I installed into a new directory in my home directory and set up a convenient symlink:
By default, Cassandra stores data in /var/lib/cassandra/. That won’t do when running as my own user, but a few changes to the config fix that problem:
The Log4J configuration needs a similar change:
At this point I was able to fire up cassandra without errors (note: the -f flag keeps the process in the foreground).
To keep things isolated, I set up a clean gemset with rvm before installing any gems. At the time of writing, the latest release of the cassandra gem didn’t support the 1.0 release of Cassandra, so I installed head from github via bundler.
Create a schema
I’m not yet sure what the best long-term strategy (and tooling) for schema management is, so for now I went with setting up a test schema via the CLI. I followed the blog schema described here, with a couple of changes for recent deprecations.
Running this through the CLI got the schema set up:
Insert some data using the Cassandra Ruby library
And so we’re ready to write some data. Here’s a quick script to connect from Ruby and set up some sample data along the lines referenced in the CLI wiki page above:
Similar thing with CQL
The cassandra gem, and the data insertion code above, interfaces with Cassandra via its Thriftapi. Recently, though, there has been a move towards a new, more SQL-like, api called CQL (syntax) which started shipping with version 0.8.
Note: in the course of trying out CQL I fired up the cqlsh (CQL shell) which ships with Cassandra. That program required a python cql module to run (more details here). I installed that using the following command (for python 2.7):
Then I put together the following script which closely follows the example above. Note that this creates a new keyspace before inserting data—I didn’t see a way to do that using the cassandra gem.
The following posts were useful in piecing together the details for installing and using cassandra and the cassandra gem: