Skip to content

Commit

Permalink
Use thriftclient.
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Weaver committed Oct 14, 2009
1 parent 3225de7 commit ce023bc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,6 @@


v0.6. Use thrift_client gem.

v0.5.6.2. Release process was busted. v0.5.6.2. Release process was busted.


v0.5.6. Real multiget. v0.5.6. Real multiget.
Expand Down
25 changes: 11 additions & 14 deletions lib/cassandra/cassandra.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,26 +52,23 @@ module Consistency
:reversed => false, :reversed => false,
:consistency => Consistency::ONE :consistency => Consistency::ONE
}.freeze }.freeze

THRIFT_DEFAULTS = {
:transport => Thrift::BufferedTransport
}.freeze


attr_reader :keyspace, :host, :port, :serializer, :transport, :client, :schema attr_reader :keyspace, :servers, :client, :schema, :thrift_client_options


# Instantiate a new Cassandra and open the connection. # Create a new Cassandra instance and open the connection.
def initialize(keyspace, host = '127.0.0.1', port = 9160, buffer = true) def initialize(keyspace, servers = "127.0.0.1:9160", thrift_client_options = {})
@is_super = {} @is_super = {}
@column_name_class = {} @column_name_class = {}
@sub_column_name_class = {} @sub_column_name_class = {}
@thrift_client_options = THRIFT_DEFAULTS.merge(thrift_client_options)


@keyspace = keyspace @keyspace = keyspace
@host = host @servers = Array(servers)
@port = port @client = ThriftClient.new(CassandraThrift::Cassandra::Client, @servers, @thrift_client_options)

transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port))
transport.open

@client = CassandraThrift::Cassandra::SafeClient.new(
CassandraThrift::Cassandra::Client.new(Thrift::BinaryProtocol.new(transport)),
transport,
!buffer)


keyspaces = @client.get_string_list_property("keyspaces") keyspaces = @client.get_string_list_property("keyspaces")
unless keyspaces.include?(@keyspace) unless keyspaces.include?(@keyspace)
Expand All @@ -84,7 +81,7 @@ def initialize(keyspace, host = '127.0.0.1', port = 9160, buffer = true)
def inspect def inspect
"#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{ "#<Cassandra:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
schema.map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ') schema.map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ')
}}, @host=#{host.inspect}, @port=#{port}>" }}, @servers=#{servers.inspect}>"
end end


### Write ### Write
Expand Down
6 changes: 3 additions & 3 deletions test/cassandra_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ class CassandraTest < Test::Unit::TestCase
include Cassandra::Constants include Cassandra::Constants


def setup def setup
@twitter = Cassandra.new('Twitter', '127.0.0.1') @twitter = Cassandra.new('Twitter', "127.0.0.1:9160", :retries => 2)
@twitter.clear_keyspace! @twitter.clear_keyspace!


@blogs = Cassandra.new('Multiblog', '127.0.0.1') @blogs = Cassandra.new('Multiblog')
@blogs.clear_keyspace! @blogs.clear_keyspace!


@blogs_long = Cassandra.new('MultiblogLong', '127.0.0.1') @blogs_long = Cassandra.new('MultiblogLong')
@blogs_long.clear_keyspace! @blogs_long.clear_keyspace!


@uuids = (0..6).map {|i| UUID.new(Time.at(2**(24+i))) } @uuids = (0..6).map {|i| UUID.new(Time.at(2**(24+i))) }
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
begin; require 'ruby-debug'; rescue LoadError; end begin; require 'ruby-debug'; rescue LoadError; end


begin begin
@test_client = Cassandra.new('Twitter', '127.0.0.1') @test_client = Cassandra.new('Twitter')
rescue Thrift::TransportException => e rescue Thrift::TransportException => e
#FIXME Make server automatically start if not running #FIXME Make server automatically start if not running
if e.message =~ /Could not connect/ if e.message =~ /Could not connect/
Expand Down

0 comments on commit ce023bc

Please sign in to comment.