2012-01-31 3 views
2

내 카산드라 클러스터에 연결 시도 [버전 1.0.6]이 스크립트를 실행에 내 샘플 스크립트Nodejs 카산드라 클라이언트 nodejs를 통해 [노드 카산드라 클라이언트]

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입니다. 먼저() 연결해야합니다. 내가 connct, 쿼리, 주변의 순서를 처리 할 수 ​​async를 사용하는 것이 좋습니다

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. 
    }); 
    }); 
}); 

, 참고로 풀 된 접속과 함께 실행될 때 같은 쿼리를 실행

+0

방법입니다 근무 등의 예를 들면 다음과 같습니다 (무시 모든 오류)입니다 당신은 async와 연결, 질의 및 닫기의 순서를 처리합니까? – olive

+0

async.series와 async.waterfall가 마음에 듭니다. –

+0

고마워, 이것이 내가 끝내고 완벽하게 작동 한 것이다. – olive

2

node.js 중고품 드라이버와 관련된 문제가 있습니다. Helenus으로 운이 더 좋았습니다.