简体   繁体   English

如何使用Ruby连接到Cassandra

[英]How to connect to Cassandra using ruby

I am new to Cassandra and was trying to achieve some simple operations like inserting data into cassandra. 我是Cassandra的新手,正在尝试实现一些简单的操作,例如将数据插入cassandra。 I am using cassandra gem to achieve this. 我正在使用卡桑德拉宝石来实现这一目标。

client = Cassandra.new('tags_logs', 'ec2-xxx-xxx-xxx.com:9160')
client.disable_node_auto_discovery!
client.get('tag_data','red')

And I get the following error: 我得到以下错误:

ThriftClient::NoServersAvailable - No live servers in ...

I'm running this code from my local machine. 我正在本地计算机上运行此代码。 And while I've no problem connecting using cassandra-cli (so it is not a firewall issue), the code refuses to work. 虽然我使用cassandra-cli进行连接没有问题 (因此这不是防火墙问题),但是代码拒绝工作。 It works perfectly when accessing Cassandra on my own local machine. 在我自己的本地计算机上访问Cassandra时,它可以完美工作

Any ideas? 有任何想法吗? Thanks, 谢谢,

Eden. 伊甸园

I recommend you to use this gem I'm developing: https://github.com/hsgubert/cassandra_migrations 我建议您使用我正在开发的宝石: https : //github.com/hsgubert/cassandra_migrations

It gives access to Cassandra through CQL3 and manages schema with migrations. 它允许通过CQL3访问Cassandra,并通过迁移管理架构。

Note: it requires Rails. 注意:它需要Rails。

For future generations: simply change the timeout ... 对于子孙后代:只需更改超时时间...

client = Cassandra.new('tags_logs', 'ec2-example-example-example.com:9160',:connect_timeout => 10000) 客户端= Cassandra.new('tags_logs','ec2-example-example-example.com:9160',:connect_timeout => 10000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM