Skip to content

Commit 9fa28c9

Browse files
committed
Refactor and update for cassandra native protocol v5 and php 8.1
1 parent 323613d commit 9fa28c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+10141
-2036
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vendor
2+
composer.lock
3+
.phpunit.result.cache
4+
phpunit-report
5+
debug-*.php

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
Cassandra client library for PHP
22
================================
33

4-
<a href="https://codeclimate.com/github/duoshuo/php-cassandra/"><img src="https://codeclimate.com/github/duoshuo/php-cassandra.png" /></a>
5-
<a href="https://scrutinizer-ci.com/g/duoshuo/php-cassandra/"><img src="https://scrutinizer-ci.com/g/duoshuo/php-cassandra/badges/quality-score.png?b=master" /></a>
6-
<a href="https://scrutinizer-ci.com/g/duoshuo/php-cassandra/"><img src="https://scrutinizer-ci.com/g/duoshuo/php-cassandra/badges/build.png?b=master" /></a>
7-
8-
Cassandra client library for PHP, which support Protocol v3 (Cassandra 2.1) and asynchronous request
4+
Cassandra client library for PHP, which supports Protocol v5 (Cassandra 4.x) and asynchronous requests.
95

106
## Features
11-
* Using Protocol v3 (Cassandra 2.1)
7+
* Using Protocol v5 (Cassandra 4.x)
128
* Support ssl/tls with stream transport layer
139
* Support asynchronous and synchronous request
1410
* Support for logged, unlogged and counter batches
@@ -23,7 +19,7 @@ Cassandra client library for PHP, which support Protocol v3 (Cassandra 2.1) and
2319

2420
## Installation
2521

26-
PHP 5.4+ is required. There is no need for additional libraries.
22+
PHP 8.1+ is required. There is no need for additional libraries.
2723

2824
If you want to use Bigint or Timestamp type, 64-bit system is required.
2925

@@ -69,12 +65,14 @@ $nodes = [
6965
'timeout' => 30, // write/recv timeout, default 30, stream transport only
7066
'persistent' => true, // use persistent PHP connection, default false, stream transport only
7167
],
72-
[ // advanced way, using SSL
68+
[ // advanced way, using SSL/TLS
7369
'class' => 'Cassandra\Connection\Stream', // "class" must be defined as "Cassandra\Connection\Stream" for ssl or tls
7470
'host' => 'ssl://10.205.48.70',// or 'tls://10.205.48.70'
7571
'port' => 9042,
7672
'username' => 'admin',
7773
'password' => 'pass',
74+
'ssl' => ['verify_peer' => false, 'verify_peer_name' => false], //disable certificate verification
75+
//'ssl' => ['cafile' => 'cassandra.pem', 'verify_peer_name'=>false] //with SSL certificate validation, no name check
7876
],
7977
];
8078

@@ -125,6 +123,16 @@ $row = $response->fetchRow(); // ArrayObject
125123
$value = $response->fetchOne(); // mixed
126124
```
127125

126+
## Iterate over result
127+
```php
128+
// Print all roles
129+
$response = $connection->querySync("SELECT role FROM system_auth.roles");
130+
foreach($response AS $rowNo => $rowContent)
131+
{
132+
echo $rowContent['role']."\n";
133+
}
134+
```
135+
128136
## Query Asynchronously
129137

130138
```php
@@ -221,20 +229,33 @@ All types are supported.
221229
// Counter
222230
new Cassandra\Type\Counter(1000);
223231

232+
// Date (a number of days +- since January 1st, 1970)
233+
new Cassandra\Type\Date(19435);
234+
new Cassandra\Type\Date(-2000);
235+
224236
// Decimal
225237
new Cassandra\Type\Decimal('0.0123');
226238

227239
// Double
228240
new Cassandra\Type\Double(2.718281828459);
229241

242+
// Duration
243+
new Cassandra\Type\Duration(['months' => 1, 'days' => 2, 'nanoseconds'=> 3]);
244+
230245
// Float
231246
new Cassandra\Type\PhpFloat(2.718);
232247

233248
// Inet
234249
new Cassandra\Type\Inet('127.0.0.1');
235250

236251
// Int
237-
new Cassandra\Type\PhpInt(1);
252+
new Cassandra\Type\PhpInt(12345678);
253+
254+
// Smallint
255+
new Cassandra\Type\Smallint(2048);
256+
257+
// Tinyint
258+
new Cassandra\Type\Tinyint(122);
238259

239260
// CollectionList
240261
new Cassandra\Type\CollectionList([1, 1, 1], [Cassandra\Type\Base::INT]);
@@ -245,6 +266,9 @@ All types are supported.
245266
// CollectionSet
246267
new Cassandra\Type\CollectionSet([1, 2, 3], [Cassandra\Type\Base::INT]);
247268

269+
// Time (nanoseconds since midnight)
270+
new Cassandra\Type\Time(18000000000000);
271+
248272
// Timestamp (unit: millisecond)
249273
new Cassandra\Type\Timestamp((int) (microtime(true) * 1000));
250274
new Cassandra\Type\Timestamp(1409830696263);
@@ -322,5 +346,12 @@ new Cassandra\Type\CollectionSet([
322346
* [shen2/cadmin](https://github.com/shen2/cadmin): Web admin panel for Cassandra, like phpmyadmin
323347

324348
## Inspired by
349+
* [duoshuo/php-cassandra](https://github.com/duoshuo/php-cassandra)
325350
* [mauritsl/php-cassandra](https://github.com/mauritsl/php-cassandra)
326351
* [evseevnn/php-cassandra-binary](https://github.com/evseevnn/php-cassandra-binary)
352+
353+
## Merged contributions for duoshuo/php-cassandra
354+
* https://github.com/arnaud-lb/php-cassandra/commit/b6444ee5f8f7079d7df80de85201b11f77e0d376
355+
* https://github.com/duoshuo/php-cassandra/pull/78
356+
* https://github.com/duoshuo/php-cassandra/pull/77
357+
* https://github.com/duoshuo/php-cassandra/pull/66

composer.json

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "duoshuo/php-cassandra",
3-
"description": "Cassandra client library for PHP, which support Protocol v3 and asynchronous request",
2+
"name": "mroosz/php-cassandra-client",
3+
"description": "Cassandra client library for PHP, which supports Protocol v5 and asynchronous requests",
44
"minimum-stability": "stable",
55
"keywords" : [
66
"cassandra",
@@ -18,12 +18,30 @@
1818
{
1919
"name": "Evseev Nikolay",
2020
"email": "[email protected]"
21+
},
22+
{
23+
"name": "Dennis Birkholz",
24+
"email": "[email protected]"
25+
},
26+
{
27+
"name": "Michael Roosz",
28+
"email": "[email protected]"
2129
}
2230
],
2331
"require": {
24-
"php": ">=5.4.0"
32+
"php": ">=8.1.0"
33+
},
34+
"require-dev": {
35+
"phpstan/phpstan": "^1.9.14",
36+
"phpunit/phpunit": "^9.5.28",
37+
"vimeo/psalm": "^5.6"
2538
},
2639
"autoload": {
2740
"psr-4": { "Cassandra\\": "src/" }
28-
}
41+
},
42+
"scripts": {
43+
"phpstan": "vendor/bin/phpstan analyse",
44+
"psalm": "vendor/bin/psalm --no-cache",
45+
"phpunit": "XDEBUG_MODE=coverage vendor/bin/phpunit --testsuite php-cassandra $@"
46+
}
2947
}

0 commit comments

Comments
 (0)