Created
October 4, 2010 02:30
-
-
Save alienrobotwizard/609178 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'java' | |
hector_lib = File.join(ENV['HOME'], "Programming/hector/releases/hector-0.7.0-18") | |
hector_target = File.join(ENV['HOME'], "Programming/hector/target") | |
Dir["#{hector_target}/*.jar", "#{hector_lib}/*.jar"].each{|jar| $CLASSPATH << jar} | |
java_import 'me.prettyprint.cassandra.serializers.StringSerializer' | |
java_import 'me.prettyprint.hector.api.Cluster' | |
java_import 'me.prettyprint.hector.api.Keyspace' | |
java_import 'me.prettyprint.hector.api.beans.HColumn' | |
java_import 'me.prettyprint.hector.api.exceptions.HectorException' | |
java_import 'me.prettyprint.hector.api.factory.HFactory' | |
java_import 'me.prettyprint.hector.api.mutation.Mutator' | |
java_import 'me.prettyprint.hector.api.query.ColumnQuery' | |
java_import 'me.prettyprint.hector.api.query.QueryResult' | |
class CassandraViaHector | |
attr_accessor :string_serializer, :cluster, :keyspace_op, :mutator, :column_query | |
def initialize host, port, keyspace | |
@string_serializer = StringSerializer.get #new serializer object for writing | |
@cluster = HFactory.getOrCreateCluster("FooCluster", "#{host}:#{port}") | |
@keyspace_op = HFactory.createKeyspace(keyspace, cluster) | |
@mutator = HFactory.createMutator(keyspace_op, string_serializer) | |
@column_query = HFactory.createStringColumnQuery(keyspace_op) | |
end | |
def insert column_family, row_key, column_name, value | |
mutator.insert(row_key, column_family, HFactory.createStringColumn(column_name, value)); | |
end | |
def get column_family, row_key, column_name | |
column_query.set_column_family(column_family).set_key(row_key).set_name(column_name) | |
column_query.execute.get.value | |
end | |
end | |
db = CassandraViaHector.new("localhost", 9160, "Keyspace1") | |
10000.times do |i| | |
db.insert("Standard1", "#{i}", "rand_val", "#{rand}") | |
end |
Author
alienrobotwizard
commented
Oct 4, 2010
- download latest cassandra source 0.7
- git clone hector java client
- make sure you have maven (sudo apt-get install maven2)
- cd hector; ./release.sh (builds the release for you)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment