我无法在使用PHP在docker容器下运行的cassandra上创建密钥空间。 连接似乎是好的,但我没有创造任何东西。 当我运行descripe keyspaces;
时,默认情况下我只创建了keyspace。
我使用thobbs/phpcassa
bundle将php与Cassandra连接起来。 我认为问题似乎出在登录和密码上。
在这捆里,我没找到我把它们放在哪里了。 当我连接到cassandra容器时,我可以通过以下命令进行连接:cqlsh-u cassandra-p cassandra 172.24.0.1 9042
下面是我在index.php上的代码
<?php
require 'vendor/autoload.php';
use phpcassa\ColumnFamily;
use phpcassa\ColumnSlice;
use phpcassa\Connection\ConnectionPool;
$servers = array("172.24.0.1:9042");
$pool = new ConnectionPool("Keyspace2", $servers);
$column_family = new ColumnFamily($pool, 'ColumnFamily1');
我可以把我的登录名和密码放在哪里?
请不要使用thobbs/phpcassa
-它很旧了,它在引擎盖下使用的是遗留的节俭协议…… 现在与Cassandra一起工作的正确方法是使用来自DataStax的PHP驱动程序。 那里完全支持身份验证(doc),如下所示:
$cluster = Cassandra::cluster()
->withCredentials("username", "password")
->build();
$session = $cluster->connect();
得到$session
之后,可以使用execute
函数执行CQL语句,例如,CREATE KEYSPACE和CREATE TABLE,如下所示:
$session->execute('CREATE TABLE ...')
我建议学习一下CQL(Cassandra Query Language),它很久以前就取代了Thrift。 很好的参考资料是“Cassandra.The definitive guide Book”--它的第三版最近发布了,可以从DataStax网站免费获得。