2012-01-31 11 views
2

私はCassandraのクラスタに接続しようとした[バージョン1.0.6]これは、スクリプトの実行に私のサンプルスクリプトNodejs Cassandraのクライアントnodejs介し[ノードCassandraのクライアント]

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

あるnode-cassandra-client

を使用して

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, 
     connectionInfo: 
     { host: 'x.x.x.x', 
     port: 9160, 
     keyspace: 'Stats', 
     timeout: 10000 }, 
     timeout: 10000 } 

    node.js:201 
      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.<anonymous> (/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) 

マイnodetool統計

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

エラーの原因は何ですか?この問題を解決するにはいくつかの助けが必要です

+0

はどのように – Tamil

答えて

12

接続内のクライアントがnullです。まず接続する必要があります()。ここでの例では、(すべてのエラーを無視します)です:プールされた接続で実行したときにFYI同じクエリを実行する

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

私は、クエリ、近くなど、connctの順序を処理するためにasyncを使用することをお勧め

+0

を働きましたあなたは接続、クエリ、非同期で閉じるの順序を処理しますか? – olive

+0

オーダー・ワークフローを保証するもの:async.seriesとasync.waterfallがあります。 –

+0

ありがとう、これは私がやったことです、そして、それは完全に働いた。 – olive

2

node.jsスリフトドライバに問題があります。私はHelenusで運が増えました。

関連する問題