Cassandra Basic Schema and Ruby Gem

by Charles Max Wood on July 24, 2011

You can get cassandra at cassandra.apache.org and the ruby gem by running:

gem install cassandra

I did run into a problem with the trift_client gem when installing. If you get a Load Error, run this.

sudo chmod 644 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/*.rb
sudo chmod 755 /usr/local/lib/ruby/gems/1.8/gems/thrift_client-0.6.3/lib/thrift_client/connection

Here are some of the Cassandra commands from the video:

#connects to the cassandra server using the Twitter keyspace
store = Cassandra.new(“Twitter”)

# create a new column family in the Twitter keyspace called Users
cf_def = CassandraThrift::CfDef.new(:keyspace => “Twitter”, :name => “Users”)
store.add_column_family(cf_def)

# add or create a row to the column family
store.insert(“Users”, “cmaxw”, {“name” => “Charles Max Wood”, “description” => “Awesome coder”})

# remove a column from a row
store.remove(“Users”, “cmaxw”, “description”)

Download 17.2 MB
Download (iPod & iPhone) 20.9 MB
Take the 2011 Readers Survey

  • Danko Master

    I have an error installing gem cassandra.

    sudo gem install cassandraBuilding native extensions.  This could take a while…ERROR:  Error installing cassandra: ERROR: Failed to build gem native extension.        /usr/bin/ruby1.9.1 extconf.rbchecking for strlcpy() in string.h… nocreating Makefile

    makegcc -I. -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FILE_OFFSET_BITS=64  -fPIC -g -O2 -Wall -Werror  -o struct.o -c struct.c

    Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/thrift-0.7.0 for inspection.

    irb(main):001:0> reqire ‘cassandra’NoMethodError: undefined method `reqire’ for main:Object from (irb):1 from /usr/bin/irb:12:in `’

    What’s wrong?

    • http://teachmetocode.com Charles Max Wood

      First, in IRB, you’ve mistyped ‘require’.

      As for the thrift gem, it looks like it’s trying to find strlcpy in the C string.h header file.

      You could try updating xcode to the latest version. (for Mac)

      On Linux, try updating your build tools and system libraries.

      I also found this for Windows (http://www.ruby-forum.com/topic/1342287)

  • Danko Master

    I install thrift (0.8.0)

    irb(main):001:0> require ‘thrift’=> true

    But…

    sudo gem install cassandraBuilding native extensions.  This could take a while…ERROR:  Error installing cassandra: ERROR: Failed to build gem native extension./usr/bin/ruby1.9.1 extconf.rbchecking for strlcpy() in string.h… nocreating Makefilemakegcc -I. -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FILE_OFFSET_BITS=64  -fPIC -g -O2 -Wall -Werror  -o protocol.o -c protocol.cgcc -I. -I/usr/include/ruby-1.9.1/i686-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -D_FILE_OFFSET_BITS=64  -fPIC -g -O2 -Wall -Werror  -o struct.o -c struct.c

    Gem files will remain installed in /var/lib/gems/1.9.1/gems/thrift-0.7.0 for inspection.Results logged to /var/lib/gems/1.9.1/gems/thrift-0.7.0/ext/gem_make.out

  • http://twitter.com/tavoav1 Gustavo Arrieta Varg

     Hello,

    You can use ruby on rails with cassandra?

    • http://teachmetocode.com Charles Max Wood

      Yes. It’s not too difficult now. I’m working hard to make it easier. Have you tried? What obstacles have you run into?

Previous post:

Next post: