使用的 Cassandra 版本是 2.0。使用 Cassandra Helenus Driver,返回的 TTL 和 TS 似乎不正确。不知道我在这里缺少什么。
这里是 npm 安装信息:
cassandra-client@0.14.7 node_modules/cassandra-client
├── node-uuid@1.4.1
├── async@0.2.9
├── thrift@0.9.0
└── whiskey@0.8.4 (gex@0.0.1, sprintf@0.1.2, rimraf@1.0.1, simplesets@1.1.6, terminal@0.1.3, logmagic@0.1.4, underscore@1.5.2, magic-templates@0.1.1, istanbul@0.1.44)
这是示例
cqlsh:mykeyspace> INSERT INTO users (user_id, fname, lname) VALUES (1749, 'john', 'smith5') using TTL 3000;
cqlsh:mykeyspace> SELECT writetime(fname) FROM users;
writetime(fname)
------------------
1379455363318000
1379280881300000
1379280882172000
1379460416737000
(4 rows)
cqlsh:mykeyspace> SELECT ttl(fname) FROM users;
ttl(fname)
------------
null
null
null
2992
(4 rows)
Node.js 代码段
var helenus = require ('helenus');
var conn = new helenus.ConnectionPool({
host : 'localhost:9160',
keyspace : 'mykeyspace',
user : '',
password : '',
timeout : 3000,
cqlVersion : '3.0.0'
//cqlVersion : '3.0.0' // specify this if you're using Cassandra 1.1 and want to use CQL 3
});
conn.on('error', function(err){
console.error(err.name, err.message);
});
conn.connect(function(err, keyspace){
if(err){
throw(err);
} else {
conn.cql("SELECT fname FROM users", function(err, results){
console.log(err, results);
console.log('Here we are!');
results.forEach(function(row){
//all row of result
row.forEach(function(name,value,ts,ttl){
//all column of row
console.log(name,value,ts,ttl);
});
});
});
}
});
这是输出
Here we are!
fname john Wed Dec 31 1969 16:00:00 GMT-0800 (PST) null
fname john Wed Dec 31 1969 16:00:00 GMT-0800 (PST) null
fname john Wed Dec 31 1969 16:00:00 GMT-0800 (PST) null
fname john Wed Dec 31 1969 16:00:00 GMT-0800 (PST) null