节点。js node-cassandra-client请求失败

时间:2022-08-11 15:47:33

I keep running into the same issue when I'm trying to query a Cassandra Server. I have npm installed node-cassandra-client version 0.9.5.

当我试图查询Cassandra服务器时,我一直遇到同样的问题。我已经安装了node-cassandra-client版本0.9.5。

var Connection = require('cassandra-client').PooledConnection;

var hosts = ['host1:9160','host2:9160'];
var cassandra = new Connection({'hosts': hosts, 'keyspace': 'keyspace'});
cassandra.on('log', function(level, message, obj) {
  console.log('log event: %s -- %j', level, message);
});
var cql = "SELECT * FROM columnFamily LIMIT 1";

cassandra.execute(cql, function(err, rows) {
  if(err) console.log("erreur à la requete");

  console.log(rows);
  cassandra.shutdown(function() {
    console.log("connectoin pool shutdown");
  });
})

It seems the connection succeed. But I keep running into the following error :

这种联系似乎成功了。但我一直在犯以下错误:

log event: info -- "connecting host:9160(1)"
log event: cql -- "SELECT * FROM columnFamily LIMIT 1"
DEBUG: 
DEBUG: /PATH/cassandra-client/node_modules/thrift/lib/thrift/connection.js:90
DEBUG:         throw e;
DEBUG:               
DEBUG: ^
DEBUG: TypeError: undefined is not a function
  at /PATH/node_modules/cassandra-client/lib/driver.js:701:5
  at /PATH/node_modules/cassandra-client/lib/driver.js:716:15
  at /PATH/node_modules/cassandra-client/lib/driver.js:453:9
  at/PATH/node_modules/cassandra-      client/node_modules/thrift/lib/thrift/connection.js:80:11
  at Object.recv_execute_cql_query (/PATH/node_modules/cassandra-client/lib/gen-nodejs/Cassandra.js:6219:12)
  at /PATH/node_modules/cassandra-cli ent/node_modules/thrift/lib/thrift/connection.js:83:37
  at Socket.<anonymous> (/PATH/node_modules/cassandra-client/node_modules/thrift/lib/thrift/transport.js:69:9)
  at Socket.emit (events.js:67:17)
  at TCP.onread (net.js:347:14)
DEBUG: Program node app.js exited with code 1

Whatever the request is, I keep having the same error.

不管请求是什么,我总是犯同样的错误。

1 个解决方案

#1


2  

I know it's a bit late, but you're calling cassandra.execute with two parameters (query and callback) while it accepts three (query, list of query parameters and callback).

我知道有点晚了,但你打电话给卡桑德拉。使用两个参数(查询和回调)执行,而它接受三个参数(查询、查询参数列表和回调)。

Try changing:

试着改变:

 cassandra.execute(cql, function(err, rows) {
     if(err) console.log("erreur à la requete");

     console.log(rows);
     cassandra.shutdown(function() {
         console.log("connectoin pool shutdown");
     });
 })

to

 cassandra.execute(cql, [], function(err, rows) {
     if(err) console.log("erreur à la requete");

     console.log(rows);
     cassandra.shutdown(function() {
         console.log("connectoin pool shutdown");
     });
 })

#1


2  

I know it's a bit late, but you're calling cassandra.execute with two parameters (query and callback) while it accepts three (query, list of query parameters and callback).

我知道有点晚了,但你打电话给卡桑德拉。使用两个参数(查询和回调)执行,而它接受三个参数(查询、查询参数列表和回调)。

Try changing:

试着改变:

 cassandra.execute(cql, function(err, rows) {
     if(err) console.log("erreur à la requete");

     console.log(rows);
     cassandra.shutdown(function() {
         console.log("connectoin pool shutdown");
     });
 })

to

 cassandra.execute(cql, [], function(err, rows) {
     if(err) console.log("erreur à la requete");

     console.log(rows);
     cassandra.shutdown(function() {
         console.log("connectoin pool shutdown");
     });
 })