【发布时间】:2014-08-27 10:02:29
【问题描述】:
我使用 Cassandra-PHP-Client-Library 库 将数据获取/设置到 Apache Cassandra。 我通过 cqlsh coomanda 行创建了一个键空间名称:
CREATE TABLE employees (
company text,
name text,
age int,
role text,
PRIMARY KEY (company,name)
);
然后也通过命令行插入了一些列:
INSERT INTO employees (company, name, age, role) VALUES ('OSC', 'eric', 38, 'ceo');
INSERT INTO employees (company, name, age, role) VALUES ('OSC', 'john', 37, 'dev');
现在我尝试从 php 插入任何数据,为此我使用库的方法 set():
$this->cassandra->set(
'employees.company',
array(
'company' => 'alicerozenberg@gmail.com',
'name' => 'Alice Rozenberg',
'age' => 45,
'role' => 'ddd'
)
);
在官方手册中说函数set()的first参数是key row(employees是列族的名字,company是key),other - 是列的名称和值。 对此,我有几个问题:
在我的情况下,行键是什么?在我指定的“CREATE”命令中,主键是“company,name”。但这不适合在函数中使用。此选项不起作用:
$this->cassandra->set(
'employees.name',
...
$this->cassandra->set(
'employees.company',
...
我改为 phpcassa 库,并对复合类型有疑问:
来自教程示例: https://github.com/thobbs/phpcassa/blob/master/examples/composites.php
// Insert a few records
$key1 = array("key", 1);
$key2 = array("key", 2);
$columns = array(
array(array(0, "a"), "val0a"),
array(array(1, "a"), "val1a"),
array(array(1, "b"), "val1b"),
array(array(1, "c"), "val1c"),
array(array(2, "a"), "val2a"),
array(array(3, "a"), "val3a")
);
谁能告诉我,对于两个行键“名称,公司”,我的情况是什么组合数组?谢谢!
【问题讨论】: