从erlang插入cassandra [英] inserting from erlang into cassandra

查看:221
本文介绍了从erlang插入cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图从Erlang R14B02(通过thrift 0.6.1)插入东西到cassandra 0.7.6

I am trying to insert something into cassandra 0.7.6 from Erlang R14B02 (through thrift 0.6.1)

我执行以下操作:


  1. 读取记录定义

  1. Read record definitions

rr(cassandra_types)。

rr(cassandra_types).

连接到cassandra

Connect to cassandra

{ok,C} = thrift_client_util:new(localhost,9160,cassandra_thrift,[{strict_read ,false},{strict_write,false},{framed,true}])。

{ok, C}=thrift_client_util:new("localhost", 9160, cassandra_thrift,[{strict_read, false}, {strict_write, false}, {framed, true}]).

尝试插入值(timestamp = 1,2 = Quorum)

Try to insert a value (timestamp=1, 2=Quorum)

Reply1 = thrift_client :call(C,'insert',[existing_keyspace,new_key,#columnPath {column_family =existing_column_family,column =existing_column},new_value,1,2])。

Reply1 = thrift_client:call(C, 'insert', ["existing_keyspace", "new_key",#columnPath{column_family = "existing_column_family", column = "existing_column"}, "new_value",1,2]).

但是nr3给我一个bad_args错误(1和2完美工作)。

But nr3 gives me a bad_args error (1 and 2 work perfectly). What would be the right arguments?

推荐答案

有关不支持的语言的API信息主要在它们的 Cassandra Thrift API文档

What API information there is for unsupported languages is largely in their Cassandra Thrift API documentation.

在Cassandra 0.7中, t提供大多数操作的键空间,因此 insert 只需要 [Key,ColumnPath,Column,ConsistencyLevel] 。在尝试插入之前,您需要调用 set_keyspace 。在erlang插入是

In Cassandra 0.7, you don't supply the keyspace for most operations, so insert just takes [Key, ColumnPath, Column, ConsistencyLevel]. You need to call set_keyspace before attempting the insert. The insert in erlang would be

Reply1 = thrift_client:call(C, 'insert',
                            [SomeKey,
                             #columnPath{column_family = "existing_column_family",
                                         column = "existing_column"},
                             #column{name="existing_column",
                                     value="new_value",timestamp=1},
                             ?cassandra_ConsistencyLevel_QUORUM]).

您的示例缺少插入我想的行键。

Your example is missing the row key for the insert I think too.

另外,请确保你总是更新C的值 - 它在每次thrift_client调用后改变。

As an aside, make sure you always update the value of C - it changes after every thrift_client call.

?cassandra_ConsistencyLevel_QUORUM是从内存。

?cassandra_ConsistencyLevel_QUORUM is 2 from memory.

这篇关于从erlang插入cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆