Skip to content

Instantly share code, notes, and snippets.

@beccam
Created September 20, 2014 01:00
Show Gist options
  • Save beccam/0475bc05810ad2e68f47 to your computer and use it in GitHub Desktop.
Save beccam/0475bc05810ad2e68f47 to your computer and use it in GitHub Desktop.
Getting Started with Apache Cassandra and the DS Ruby Driver
require 'cassandra'
cluster = Cassandra.connect
#cluster.each_host do |host|
# puts "Host #{"127.0.0.1"}: id=#{"6123e2c1-e3ca-4d08-a544-1315b2f399f1"} datacenter=#{"datacenter1"} rack=#{"rack1"}"
#end
keyspace = 'demo'
session = cluster.connect(keyspace)
session.execute("INSERT INTO users (lastname, age, city, email, firstname) VALUES ('Jones', 35, 'Austin', '[email protected]', 'Bob')")
session.execute("SELECT firstname, age FROM users WHERE lastname='Jones'").each do |row|
p "Firstname = #{row['firstname']}, Lastname = #{row['lastname']}, Age = #{row['age']}"
end
session.execute("UPDATE users SET age = 36 WHERE lastname = 'Jones'")
session.execute("SELECT firstname, age FROM users WHERE lastname='Jones'").each do |row|
p "Firstname = #{row['firstname']}, Lastname = #{row['lastname']}, Age = #{row['age']}"
end
session.execute("DELETE FROM users WHERE lastname = 'Jones'")
session.execute("SELECT * FROM users").each do |row|
p "Firstname = #{row['firstname']}, Lastname = #{row['lastname']}, Age = #{row['age']}"
end
@mhelfer
Copy link

mhelfer commented May 26, 2015

cluster = Cassandra.connect

returns :
getting_started.rb:3:in <top (required)>': undefined methodconnect' for Cassandra:Module (NoMethodError)
from -e:1:in load' from -e:1:in

'

Looks like it should be changed to Cassandra.cluster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment