Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: can't use with credentials #61

Open
Stajor opened this issue Feb 10, 2015 · 1 comment
Open

BUG: can't use with credentials #61

Stajor opened this issue Feb 10, 2015 · 1 comment

Comments

@Stajor
Copy link

Stajor commented Feb 10, 2015

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
Copy link
Author

Stajor commented Mar 2, 2015

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)) {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant