使用 GatewayWorker + redis 使用出现问题

0

使用 GatewayWorker + redis 使用出现问题,


我在 Events.php 中做如下处理


public static function onWorkerStart($businessWorker) 中初始化redis 

$redis = new redis();
$redis -> connect('127.0.0.1',6379);
echo "启动redis\n";

public static function onMessage($client_id, $message) 中存储数据

$redis->zAdd($key, $i, $redis_str);

但是启动后,显示如下错误:


PHP Notice:  Undefined variable: redis in /GatewayWorker/Applications/YourApp/Events.php on line 149

Notice: Undefined variable: redis in /GatewayWorker/Applications/YourApp/Events.php on line 149
PHP Fatal error: Call to a member function zAdd() on a non-object in /GatewayWorker/Applications/YourApp/Events.php on line 149

Fatal error: Call to a member function zAdd() on a non-object in /GatewayWorker/Applications/YourApp/Events.php on line 149
WORKER EXIT UNEXPECTED E_ERROR Call to a member function zAdd() on a non-object in /GatewayWorker/Applications/YourApp/Events.php on line 149
worker exit with status 65280
启动redis

不晓得是何原因哦,偶是新手,请各位大哥多多指点,感激不尽。

已邀请:

damao - phper

赞同来自:

哈哈,php基础不过关。
给你个手册学习下
http://php.net/manual/zh/language.variables.scope.php

要回复问题请先登录注册