Cassandra erlang client.
Switch branches/tags
Nothing to show
Pull request Compare This branch is 60 commits ahead, 1 commit behind varnit:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Cassanderl version 0.4


To start cassanderl, you will need to configure a section in your application config file this is the basic configuration:

   [{hostname, ""},
    {port, 9160},
    {default_keyspace, "big_data"},
    {worker_pool_size, 10},
    {recycle_count, 5000}

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.
  • recycle_count - After this many ops on the connection, it is recycled. It is useful because it can avoid leakage of memory and because in a cluster-load-balancing operation you want progress so timed-out hosts get into the round-robin consideration again. Default is 150, but it does not hurt to up it a lot.

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


Configuring for Load-balanced parallel cluster access

Like above, you need configuration into your application:

   [{hostnames, [{"", 9160},
                 {"", 9160},
                 {"", 9160}]}, % Scale to 11
    {default_keyspace, "bigger_data"},
    {worker_pool_size, 30},
    {recycle_count, 1500}]},

Note the omission of a hostname and port key, but the inclusion of the key hostnames. This means that cassanderl should be configured for multiple load-balanced connections in the cluster. Note that the value of recycle_count matter. Suppose that a node has been down for a while. Then the recycle_count ensures that if the node comes up again, it will be used by the system rather than sit idle to the side.

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.



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.