魔术方法,方法名会映射为Redis指令,参数作为Redis指令的参数。
function swoole_redis->__call(string $command, array $params);
Redis服务器除了作为内存存储之外,还可以作为一个消息通道服务器。SwooleRedis客户端也支持了Redis的订阅/发布消息指令。
与普通的存储指令不同,消息订阅/发布指令不是请求响应式的。
onMessage
事件回调函数subscribe
命令后,只能执行subscribe
, psubscribe
,unsubscribe
,punsubscribe
这4条命令$client = new swoole_redis;
$client->on('message', function (swoole_redis $client, $result) {
var_dump($result);
static $more = false;
if (!$more and $result[0] == 'message')
{
echo "subscribe new channel\n";
$client->subscribe('msg_1', 'msg_2');
$client->unsubscribe('msg_0');
$more = true;
}
});
$client->connect('127.0.0.1', 6379, function (swoole_redis $client, $result) {
echo "connect\n";
$client->subscribe('msg_0');
});
function callback(swoole_redis $redis, bool $result);
$redis->errCode
获得错误码,读取$redis->errMsg
获得错误消息$client->get('key', function (swoole_redis $client, $result) {
var_dump($result);
});