读 取哨兵信息
$hostname = '172.16.1.33';
$port = 27001;
$socket = @stream_socket_client('tcp://' . $hostname . ':' . $port . '');
if (!$socket) {die('连接错误');}
$command = "*2\r\n$8\r\nSENTINEL\r\n$7\r\nmasters\r\n";
fwrite($socket, $command);
/**
* redis解析应答
*
@author
Zhenxun Du <5552123
@qq
.com>
*
@date
2017-8-9 17:08:32
*
@param
resource $handler
*
@return
array
*/
function
redisParseResponse
(
$handler
)
{
$line
=
fgets
(
$handler
);
$type
=
$line[
0
]
;
$line_num
= (int)
substr
(
trim
(
$line
),
1
);
switch
(
$type
) {
case
'$'
:
// Bulk replies
$length
=
$line_num
+
2
;
//前面1个符号加后换行
$block
=
fread
(
$handler
,
$length
);
return
$block
;
case
'*'
:
// Multi-bulk replies
$data
=
array
();
for
(
$i
=
0
;
$i
<
$line_num
;
$i
++
) {
$data[]
=
redisParseResponse
(
$handler
);
}
return
$data
;
}
}
监控
/usr/local/redis/redis-cli -h 172.16.1.33 -p 7002 -a 6e4d98540d8d333a69c6406f819ad554 -n 15 monitor|grep "queues:abc"