php-cassandra-binary icon indicating copy to clipboard operation
php-cassandra-binary copied to clipboard

BUG: can't use with credentials

Open Stajor opened this issue 10 years ago • 1 comments

can't connect to cassandra if I use host as a key and username, password as a value

$nodes = [
    '192.168.0.2:8882' => [ 'username' => 'admin', 'password' => 'pass']
];

The bug in Cassandra/Cluster.php in method getRandomNode

after shuffle($this->nodes); the host become zero

Stajor avatar Feb 10 '15 13:02 Stajor

My solution

    public function getRandomNode() {
        if (empty($this->nodes)) throw new ClusterException('Node list is empty.');

        $array_random_assoc = function($arr, $num = 1) {
            $keys = array_keys($arr);
            shuffle($keys);

            $r = array();
            for ($i = 0; $i < $num; $i++) {
                $r[$keys[$i]] = $arr[$keys[$i]];
            }
            return $r;
        };

        $this->nodes = $array_random_assoc($this->nodes, count($this->nodes));

//      shuffle($this->nodes);
        while(!empty($this->nodes)) {
...

Stajor avatar Mar 02 '15 09:03 Stajor