Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Clojure client library for Apache Cassandra

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src .close of the client provided
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 README
Octocat-spinner-32 project.clj
README
Cassandra clojure client library.
Inspired by clojure-cassandra project, while support new version of Cassandra (0.6.1).
I take a different approach to implement it, so it does not share any code with clojure-cassandra project.

== Idea ==
Treat key space as database.
Treat column family as table.
Treat a table as a 2-dimension key-value store.

for instance,
   in table "planet", "earth" has attributes, such as "radius": 3000, "countries": 200.

   so, you can get- and set- attribute(s) of a primary key.

== Caution ==
To support TimeUUID ordering in Cassandra (http://wiki.apache.org/cassandra/FAQ#working_with_timeuuid_in_java),
I use the mentioned uuid library, while it does not exist in well known maven repositories, you may need to download it
manually.
If you do not care about the TimeUUID things, just ignore the library.

== Usage ==

(use 'cassandra.client)

(def table (-> (mk-client "localhost" 9160)
	       (key-space "Keyspace1")
	       (column-family "Standard1")))
or

(def table (mk-cf-spec "localhost" 9160 "keyspace1" "Standard1"))

;; Get Attribute
(get-attr table "foo" :hello)

;; Set attribute
(set-attr! table "foo" :hello "world!")

;;Get Attributes (batch)
(get-attrs table "foo" [:foo :bar])

;;Get all attributes
(get-attrs table "foo")

;;Set Attributes (Using Cassandra 0.6's batch mutation)
(set-attrs! table "foo" {:foo "?" :bar "!"})

== Encoder/Decoder ==
You can specify decoder to read data from a keyspace, and encoder on how to save it:

(keyspace "Standard1" :encoder myencoder :decoder mydecoder)

where encoder is a function take an object, transfer to byte[], and decoder does vice versa.

By default the client use clojure reader as encoder/decoder.

== Consistent level ==
You should specify the consistent level when defining keyspace with options read-level and write-level:

For instance:
(keyspace "Standard1" :read-level :quorom :write-level :one)

== Collections & TimedUUID ==
To support order preserved collection, client use TimedUUID as column key, but it is not
compatitable with default decoder. You must explicitly let the client know it.
To save and load a collection, you do:

(add-collection! table "foo" [{:foo "bar"} {:foo "baz"}])

(get-collection table "foo")
;; returns a map which keys are uuids, and values are the saved collection

== TODO ==
* Inverted index
* Map-reduce (?)
Something went wrong with that request. Please try again.