File tree Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Original file line number Diff line number Diff line change @@ -31,26 +31,20 @@ public function appendNode($host) {
31
31
*/
32
32
public function getRandomNode () {
33
33
if (empty ($ this ->nodes )) throw new ClusterException ('Node list is empty. ' );
34
- shuffle ($ this ->nodes );
35
- while (!empty ($ this ->nodes )) {
36
- $ host = end ($ this ->nodes );
37
- try {
38
- if ((array )$ host === $ host ) {
39
- $ nodeKey = key ($ this ->nodes );
40
- $ node = new Node ($ nodeKey , $ host );
41
- unset($ this ->nodes [$ nodeKey ]);
42
- } else {
43
- $ node = new Node ($ host );
44
- unset($ this ->nodes [$ host ]);
45
- }
46
- break ;
47
- } catch (\InvalidArgumentException $ e ) {
48
- trigger_error ($ e ->getMessage ());
34
+ $ nodeKey = array_rand ($ this ->nodes );
35
+ $ node = $ this ->nodes [$ nodeKey ];
36
+ try {
37
+ if ((array )$ node === $ node ) {
38
+ $ node = new Node ($ nodeKey , $ node );
39
+ unset($ this ->nodes [$ nodeKey ]);
40
+ } else {
41
+ $ node = new Node ($ nodeKey );
42
+ unset($ this ->nodes [$ nodeKey ]);
49
43
}
44
+ } catch (\InvalidArgumentException $ e ) {
45
+ trigger_error ($ e ->getMessage ());
50
46
}
51
47
52
- if (empty ($ node )) throw new \InvalidArgumentException ('Incorrect connection parameters for all nodes. ' );
53
-
54
48
return $ node ;
55
49
}
56
50
}
You can’t perform that action at this time.
0 commit comments