Created
September 20, 2014 01:00
-
-
Save beccam/0475bc05810ad2e68f47 to your computer and use it in GitHub Desktop.
Getting Started with Apache Cassandra and the DS Ruby Driver
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cluster = Cassandra.connect
returns :
'getting_started.rb:3:in
<top (required)>': undefined method
connect' for Cassandra:Module (NoMethodError)from -e:1:in
load' from -e:1:in
Looks like it should be changed to Cassandra.cluster