1
|
|
|
<?php |
2
|
|
|
namespace PHPDaemon\Clients\Redis; |
3
|
|
|
|
4
|
|
|
use PHPDaemon\Core\CallbackWrapper; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @package NetworkClients |
8
|
|
|
* @subpackage RedisClient |
9
|
|
|
* @author Efimenko Dmitriy <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class AutoScan |
12
|
|
|
{ |
13
|
|
|
use \PHPDaemon\Traits\ClassWatchdog; |
14
|
|
|
use \PHPDaemon\Traits\StaticObjectWatchdog; |
15
|
|
|
|
16
|
|
|
protected $conn; |
17
|
|
|
|
18
|
|
|
protected $cmd; |
19
|
|
|
|
20
|
|
|
protected $cursor = 0; |
21
|
|
|
|
22
|
|
|
protected $args; |
23
|
|
|
|
24
|
|
|
protected $limit = false; |
25
|
|
|
|
26
|
|
|
protected $num = 0; |
27
|
|
|
|
28
|
|
|
protected $isFreeze = false; |
29
|
|
|
|
30
|
|
|
protected $cb; |
31
|
|
|
|
32
|
|
|
protected $cbEnd; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor |
36
|
|
|
* @param Pool $pool Redis pool or connection |
37
|
|
|
* @param string $cmd Command |
38
|
|
|
* @param array $args Arguments |
39
|
|
|
* @param cllable $cbEnd Callback |
|
|
|
|
40
|
|
|
* @param integer $limit Limit |
|
|
|
|
41
|
|
|
*/ |
42
|
|
|
public function __construct($pool, $cmd, $args = [], $cbEnd = null, $limit = false) |
43
|
|
|
{ |
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
|
|
|
} elseif ($a !== null) { |
58
|
|
|
break; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
if ($cbEnd !== null) { |
62
|
|
|
$this->cbEnd = CallbackWrapper::wrap($cbEnd); |
63
|
|
|
} |
64
|
|
|
$this->doIteration(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function doIteration() |
68
|
|
|
{ |
69
|
|
|
if ($this->isFreeze) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$args = $this->args; |
74
|
|
|
array_unshift($args, $this->cursor); |
75
|
|
|
$args[] = function ($redis) { |
76
|
|
|
$this->conn = $redis; |
77
|
|
|
$this->cursor = $redis->result[0]; |
78
|
|
|
$func = $this->cb; |
79
|
|
|
$func($redis); |
80
|
|
|
|
81
|
|
|
if (!is_numeric($redis->result[0]) || !$redis->result[0] || ($this->limit && ++$this->num > $this->limit)) { |
82
|
|
|
$func = $this->cbEnd; |
83
|
|
|
$func($redis, $this); |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
$this->doIteration(); |
87
|
|
|
}; |
88
|
|
|
$func = [$this->conn, $this->cmd]; |
89
|
|
|
$func(... $args); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function freeze() |
93
|
|
|
{ |
94
|
|
|
$this->isFreeze = true; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function run() |
98
|
|
|
{ |
99
|
|
|
$this->isFreeze = false; |
100
|
|
|
$this->doIteration(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function reset() |
104
|
|
|
{ |
105
|
|
|
$this->num = 0; |
106
|
|
|
$this->isFreeze = false; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for
@param
annotations 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.