PHPCassa -当使用uuid时间戳作为键时不能插入


PHPCassa - Can't insert when using uuid timestamp as key

我正试图将数据存储到cassandra中,并按时间排序。使用TimeUUIDType作为键时遇到问题。

phpcassa…

Fatal error: Uncaught exception 'cassandra_InvalidRequestException' 
with message 'TimeUUID   should be 16 or 0 bytes (6)'

这在调用insert方法时发生…

$pool = new ConnectionPool("Keyspace1", array("localhost:9160"));
$column_family = new ColumnFamily($pool, 'users');
$column_family->insert(CassandraUtil::uuid1(), array('name' => 'value'));

我使用cassandra-cli用下面的命令创建了一个测试表…

CREATE COLUMN FAMILY users WITH comparator = TimeUUIDType;

comparator适用于列名,而不是行键。如果您希望行键为timeuuid,则应该设置为key_validation_class

你得到这个异常是因为Cassandra期待一个TimeUUID作为列名,但是你传递的是一个正常的字符串