Cassandra的API是CQL(Cassandra Query Language),要使用CQL,需要先连接到集群。连接的方式:
(1)使用cqlsh;
(2)通过Cassandrad的客户端驱动程序。
注:使用CQLSH前请先安装Python 2.7和python-setuptools,并将cql模块装到python。详细操作请参考http://it.zhaozhao.info/archives/8057
CQLSH
cqlsh是用于让CQL和Cassandra进行交互的命令行脚本。每个Cassandra压缩包中都会自动提供,可以在bin目录下找到可执行文件。 它连接到在命令行上指定的单个节点。 例如:
$ bin/cqlsh localhost
Connected to Test Cluster at localhost:9042.
[cqlsh 5.0.1 | Cassandra 3.8 | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh> SELECT cluster_name, listen_address FROM system.local;
cluster_name | listen_address
--------------+----------------
Test Cluster | 127.0.0.1
(1 rows)
cqlsh>
关于CQL的使用会在之后专门详细的讲解,读者先做个稍微的了解
客户端驱动
许多客户端驱动程序由社区提供,以下提供已知驱动程序的列表。 您应参考每个驱动程序的文档以获取有关如何使用它们的更多信息。
Java
Python
Ruby
C# / .NET
Nodejs
PHP
C++
Scala
Clojure
Erlang
Go
Haskell
Rust