您的位置:首页 > 编程语言 > Ruby

Install Cassandra with Ruby 1.9.1 on Windows

2010-02-28 03:51 190 查看
To get it done is not easy. I spent a whole day to figure out the various compatibility issues along the way out.

Now there still might be potential issues, but it works by my rough test.

Step 1: Install Apache Cassandra

You may know that the Ruby gem cassandra will do it for you.

To me, I simply want to keep Cassandra independent from Ruby stuff, to ease the upgrade and administration.

Refer to my blog "Setup Cassandra on Windows"

(http://blog.csdn.net/goodxp/archive/2010/02/26/5327732.aspx) for details.

Step 2: Install Thrift (0.2.0)

If you do "gem install cassandra", it should install thrift automatically (being a dependency).

However, there is a compatibility issue on thrift with Ruby 1.9, so to fail Cassandra gem installation.

It will be better to install thrift first and fix it before installing cassandra gem.

Refer to my blog "fix thrift 0.2.0 installation with ruby 1.9.1"

(http://blog.csdn.net/goodxp/archive/2010/02/28/5333145.aspx) for details.

Step 3: Install gem Cassandra

This part is easy:

$ gem install cassandra

Do NOT do this: "$ cassandra_helper cassandra". It does not work.

I did not dig deeper since I already have a working up-to-date version of Cassandra 0.5.0 installed.

Switch to Cassandra bin folder and start cassandra server:

$ cassandra -f

Open another command console window:

$ irb

irb> require 'rubygems'

irb> require 'cassandra'

If you see a warning pop-up window asking for "msvcrt-ruby18.dll", do this:

irb> quit

$ gem uninstall json

Don't worry, Ruby 1.9 has a good json support.

Now run irb again as above, and then:

irb> include Cassandra::Constants

irb> db = Cassandra.new 'Keyspace1'

irb> niceguy = {'name' => 'goodxp'}

irb> db.insert (:Standard1, '10', niceguy)

Keyspace1 and Standard1 are the sample config for Cassandra. This should work if you did not change schema yet.

Now we can check whether the data were inserted. To be sure, let's use cassandra command line client:

irb> quit

$ cassandra-cli

cassandra> connect localhost/9160

cassandra> get Keyspace1.Standard1['10']

You should see the niceguy 'name' 'goodxp' shows up. It means your Ruby API just works.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: