|
1
|
|
|
<?php |
|
2
|
|
|
namespace PHPDaemon\Clients\Redis; |
|
3
|
|
|
|
|
4
|
|
|
use PHPDaemon\Core\Daemon; |
|
5
|
|
|
use PHPDaemon\Core\Debug; |
|
6
|
|
|
use PHPDaemon\Core\CallbackWrapper; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @package NetworkClients |
|
10
|
|
|
* @subpackage RedisClient |
|
11
|
|
|
* @author Efimenko Dmitriy <[email protected]> |
|
12
|
|
|
*/ |
|
13
|
|
|
class AutoScan { |
|
14
|
|
|
use \PHPDaemon\Traits\ClassWatchdog; |
|
15
|
|
|
use \PHPDaemon\Traits\StaticObjectWatchdog; |
|
16
|
|
|
|
|
17
|
|
|
protected $conn; |
|
18
|
|
|
|
|
19
|
|
|
protected $cmd; |
|
20
|
|
|
|
|
21
|
|
|
protected $cursor = 0; |
|
22
|
|
|
|
|
23
|
|
|
protected $args; |
|
24
|
|
|
|
|
25
|
|
|
protected $limit = false; |
|
26
|
|
|
|
|
27
|
|
|
protected $num = 0; |
|
28
|
|
|
|
|
29
|
|
|
protected $isFreeze = false; |
|
30
|
|
|
|
|
31
|
|
|
protected $cb; |
|
32
|
|
|
|
|
33
|
|
|
protected $cbEnd; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Constructor |
|
37
|
|
|
* @param Pool $pool Redis pool or connection |
|
38
|
|
|
* @param string $cmd Command |
|
39
|
|
|
* @param array $args Arguments |
|
40
|
|
|
* @param cllable $cbEnd Callback |
|
|
|
|
|
|
41
|
|
|
* @param integer $limit Limit |
|
|
|
|
|
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct($pool, $cmd, $args = [], $cbEnd = null, $limit = false) { |
|
44
|
|
|
$this->conn = $pool; |
|
45
|
|
|
$this->cmd = $cmd; |
|
46
|
|
|
$this->args = empty($args) ? [] : $args; |
|
47
|
|
|
$this->limit = $limit; |
|
|
|
|
|
|
48
|
|
|
if (is_numeric($this->args[0])) { |
|
49
|
|
|
array_shift($this->args); |
|
50
|
|
|
} |
|
51
|
|
|
for ($i = sizeof($this->args) - 1; $i >= 0; --$i) { |
|
52
|
|
|
$a = $this->args[$i]; |
|
53
|
|
|
if ((is_array($a) || is_object($a)) && is_callable($a)) { |
|
54
|
|
|
$this->cb = CallbackWrapper::wrap($a); |
|
55
|
|
|
$this->args = array_slice($this->args, 0, $i); |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
elseif ($a !== null) { |
|
59
|
|
|
break; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
if ($cbEnd !== null) { |
|
63
|
|
|
$this->cbEnd = CallbackWrapper::wrap($cbEnd); |
|
64
|
|
|
} |
|
65
|
|
|
$this->doIteration(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function freeze() { |
|
69
|
|
|
$this->isFreeze = true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function run() { |
|
73
|
|
|
$this->isFreeze = false; |
|
74
|
|
|
$this->doIteration(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function reset() { |
|
78
|
|
|
$this->num = 0; |
|
79
|
|
|
$this->isFreeze = false; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function doIteration() { |
|
83
|
|
|
if ($this->isFreeze) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$args = $this->args; |
|
88
|
|
|
array_unshift($args, $this->cursor); |
|
89
|
|
|
$args[] = function($redis) { |
|
90
|
|
|
$this->conn = $redis; |
|
91
|
|
|
$this->cursor = $redis->result[0]; |
|
92
|
|
|
call_user_func($this->cb, $redis); |
|
93
|
|
|
|
|
94
|
|
|
if (!is_numeric($redis->result[0]) || !$redis->result[0] || ($this->limit && ++$this->num > $this->limit)) { |
|
95
|
|
|
call_user_func($this->cbEnd, $redis, $this); |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
$this->doIteration(); |
|
99
|
|
|
}; |
|
100
|
|
|
call_user_func_array([$this->conn, $this->cmd], $args); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.