-
Notifications
You must be signed in to change notification settings - Fork 19
Counters
pingles edited this page Sep 28, 2011
·
1 revision
Counters were added in the 0.8x branch of Cassandra. clj-hector provides basic support currently.
Firstly, you'll need to make sure you've created a column family that has the default validator set to CounterColumnType. Using the clj-hector.ddl/add-keyspace
function you can create a compatible column family as follows:
(ddl/add-keyspace *cluster* {:name "Keyspace"
:strategy :local
:replication 1
:column-families [{:name cf
:validator :counter}]})
Once you've defined your keyspace (and column family), you can store counter values.
For example, to store in the column family above, use the clj-hector.core/put-counter
function:
(put-counter ks cf pk {"first-counter" 1 "other-counter" 2})
And the value can be queried with
(get-counter-columns ks cf pk ["name" "other"] {:n-serializer :string :v-serializer :long})