Skip to content

pingles/clj-cassandra

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 (?)

About

Clojure client library for Apache Cassandra

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages