public function send(callable $callback) { $client = new \swoole_redis(); $calltime = microtime(true); $key = md5($calltime . $this->_config['host'] . $this->_config['port'] . rand(0, 10000)); $method = $this->_method; $params = $this->_argv; $db = (int) $this->_config['db']; array_push($params, function (\swoole_redis $redis, $result) use($callback, $key, $calltime) { call_user_func_array($callback, ['r' => 0, 'key' => $key, 'calltime' => $calltime, 'data' => $result]); $redis->close(); }); $client->connect($this->_config['host'], $this->_config['port'], function (\swoole_redis $client, $result) use($method, $params, $db) { $callback = end($params); if ($result == false) { call_user_func_array($callback, [$client, ['errCode' => $client->errCode, 'errMsg' => $client->errMsg]]); return; } if ($db) { $client->select($db, function (\swoole_redis $client, $result) use($method, $params, $callback) { if ($result == false) { call_user_func_array($callback, [$client, ['errCode' => $client->errCode, 'errMsg' => $client->errMsg]]); return; } call_user_func_array([$client, $method], $params); }); return; } call_user_func_array([$client, $method], $params); }); unset($this->_method, $this->_argv); }