Skip to content
This repository

cassandra erlang client

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 include
Octocat-spinner-32 src
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 rebar
Octocat-spinner-32 rebar.config
README.md

Cassanderl version 0.4

Configuration

To start cassanderl, you will need to configure a section in your application config file:

 {cassanderl,
   [{hostname, "cassandra.talented-startup.com"},
    {port, 9160},
    {default_keyspace, "big_data"},
    {worker_pool_size, 10}
   ]},

The options are as follows:

  • hostname - The hostname to connect to
  • port - The port to connect to. Cassandra RPC is on port 9160 by default
  • default_keyspace - If you omit setting a keyspace, this keyspace will be used for a newly formed connection.
  • worker_pool_size - The size of the worker pool. How many concurrent resource-connections do you allow to the cassandra cluster.

Second, you will need to start up cassanderl (or make it part of your boot script):

 application:start(cassanderl).

Example of Usage

To use Cassanderl, you must first ask it for the current configuration.

{ok, Config} = cassanderl:get_info().

This will return the current dispatcher configuration. Cassanderl spawns a pool of dispatchers by default which it then uses whenever you want to access your Cassandra cluster. The hostname and portname of the cluster will be the defaults as well when doing this.

To issue a call to Cassandra, issue:

cassanderl:call(Config, describe_keyspace, ["keyspace1"]).

Which performs a low-level call to Cassandra with the given configuration, the given (thrift) method and the given parameters to the call.

The module cassanderl has certain helpers as well for often-executed functions.

Commands

Add

To issue an add towards Cassandra, do the following:

 {ok, Config} = cassanderl:get_info(),
 CP = cassanderl:column_parent(<<"superhero_stats">>),
 {ok, CassandraResult} =
   add(Config, <<"gotham city">>, CP, {<<"batmans_spotted">>, 7}, 1).

In this example, we first generate a "column parent" for the column family. There are no super-columns here, so just referring to the superhero stats is enough. The CP acts like an accessor pattern on the data we wish to update and can be reused in subsequent calls if we want.

Finally, we increment a counter on the Gotham City row. We spotted some Batmans. The last parameter is the consistency level desired.

Get Slice

A slice is a range of columns ordered by some ordering function (Usually lexicographic on the string). To get all superheroes in gotham city, we could do:

  SliceRange = slice(<<"a">>, <<"z">>),
  get_slice(Config, <<"gotham_city">>, CP, SliceRange, 1)

to obtain Batman, Catwoman (Rrrrrawr!), Superman, Poison Ivy, and so on. Ok, some of those may not be superheroes exactly, but surely you get the idea.

Something went wrong with that request. Please try again.