Concurrent.php
1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/12/15
* Time: 上午2:02
*/
namespace Hood\Concurrent\Yar;
use Hood\Core\Root;
class Concurrent extends Root
{
private $uri;
public function __construct($uri)
{
parent::__construct();
$this->uri = $uri;
}
/**
* 注册一个并行的服务调用
* @param $uri
* @param $method
* @param $parameters
* @param string $callback
*/
public function call($uri, $method, $parameters, $callback = '')
{
\Yar_Concurrent_Client::call($uri, $method, $parameters, $callback);
}
/**
* 链式调用
* @param $method
* @param $parameters
* @param string $callback
* @return $this
*/
public function calls($method, $parameters, $callback = '')
{
$this->call($this->uri, $method, $parameters, $callback);
return $this;
}
/**
* 发送所有注册的并行调用
* @param string $callback
* @param callable $errorCallback
*/
public function loop($callback = '', $errorCallback = '')
{
\Yar_Concurrent_Client::loop($callback, $errorCallback);
}
/**
* 缓存tag
* @param $tagName
* @return $this
*/
public function tag($tagName)
{
$this->_cacheTagName = $tagName;
return $this;
}
/**
* 缓存key
* @param string $key
* @param null $prefix
* @return $this
*/
public function key($key)
{
$this->_cacheKey = (string)$key;
return $this;
}
/**
* 缓存时间
* @param $expire
* @return $this
*/
public function expire($expire)
{
$this->_cacheExpire = (int)$expire;
return $this;
}
}