Nodejs Cassandra Client [node-cassandra-client]

I tried connecting to my cassandra cluster [version 1.0.6] via nodejs using node-cassandra-client

This is my sample script

var Connection = require('cassandra-client').Connection;
var con = new Connection({host:'x.x.x.x', port:9160, keyspace:'Stats', timeout:10000});
con.execute('UPDATE TestCF ?=? WHERE key=?', ['cola', '1', '20120132'], function(err) {
    if (err) {
    } else {

On executing the script

The "sys" module is now called "util". It should have a similar interface.
    node-cassandra-client.driver: connecting x.x.x.x:9160 {}
    { validators: {},
      client: null,
       { host: 'x.x.x.x',
         port: 9160,
         keyspace: 'Stats',
         timeout: 10000 },
      timeout: 10000 }

            throw e; // process.nextTick error, or 'error' event on first tick
    TypeError: Cannot call method 'execute_cql_query' of null
        at [object Object].execute (/home/tamil/workspace/TestProjects/node-cass/node_modules/cassandra-client/lib/driver.js:367:17)
        at Object. (/home/tamil/workspace/TestProjects/node-cass/index.js:5:5)
        at Module._compile (module.js:432:26)
        at Object..js (module.js:450:10)
        at Module.load (module.js:351:31)
        at Function._load (module.js:310:12)
        at Array.0 (module.js:470:10)
        at EventEmitter._tickCallback (node.js:192:40)

My nodetool stats

Address         DC          Rack        Status State   Load            Owns    Token                                       
x.x.x.x         datacenter1 rack1       Up     Normal  1.03 MB         100.00% 0

What would be the error reason? and Need some help to fix this

Problem courtesy of: Tamil


the client inside your connection is null. You need to connect() first. Here’s an example (ignores all errors):

var con = new Connection({host:'x.x.x.x', port:9160, keyspace:'Stats', timeout:10000});
con.connect(function(err) {
  con.execute('SELECT COUNT(*) FROM TestCF', [], function(err, rows) {
    con.close(function(err) {
      // you're done now.

I recommend using async
to handle the ordering of connct, query, close, etc.

Solution courtesy of: Gary Dusbabek

Node.js Recipes责编内容来自:Node.js Recipes (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Nodejs Cassandra Client [node-cassandra-client]

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录