yiisoft / yii2-redis

Yii 2 Redis extension.
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
452 stars 183 forks source link

yii2-redis,$redis->eval() error #159

Open yii-bot opened 5 years ago

yii-bot commented 5 years ago

This issue has originally been reported by @alu12138 at https://github.com/yiisoft/yii2/issues/16613. Moved here by @samdark.


What steps will reproduce the problem?

$redis = \Yii::$app->redis; $redis->eval($lua, array("data1", "date2", 1, 1,time()), 2);

What is the expected result?

Executed successfully

What do you get instead?

{ "name": "PHP Warning", "message": "mb_strlen() expects parameter 1 to be string, array given", "code": 2, "type": "yii\base\ErrorException", "file": "/vendor/yiisoft/yii2-redis/src/Connection.php", "line": 677, "stack-trace": [ "#0 [internal function]: yii\base\ErrorHandler->handleError(2, 'mb_strlen() exp...', '/vendor...', 677, Array)", "#1 /vendor/yiisoft/yii2-redis/src/Connection.php(677): mb_strlen(Array, '8bit')", "#2 /vendor/yiisoft/yii2-redis/src/Connection.php(630): yii\redis\Connection->executeCommand('EVAL', Array)", "#3 /frontend/controllers/v1/MessageController.php(322): yii\redis\Connection->__call('eval', Array)", "#4 /frontend/controllers/v1/MessageController.php(322): yii\redis\Connection->eval('\r\nlocal data...', Array, 4)", "#5 [internal function]: frontend\controllers\v1\MessageController->actionOpen()", "#6 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)", "#7 /vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)", "#8 /vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('open', Array)", "#9 /vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('v1/message/open', Array)", "#10 /vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))", "#11 /frontend/web/index.php(17): yii\base\Application->run()", "#12 {main}" ] }

Additional info

Q A
Yii version ~2.0.6
PHP version 5.6
Operating system centos
alu12138 commented 5 years ago

Yii version 2.0.15.1

rob006 commented 5 years ago

You should pass arguments separately instead of using array.

$redis->eval($lua, "data1", "date2", 1, 1, time(), 2);
alu12138 commented 5 years ago

Fail. Redis::eval() expects at most 3 parameters, 7 given

alu12138 commented 5 years ago

这个问题是,yii2-redis执行命令有一个判断,mb_strlen()统计参数字数,数组作为参数将会报错。不知道该怎么兼容。 The problem is that the yii2-redis execution command has a judgment, mb_strlen() counts the number of arguments, and the array as an argument will report an error. I don't know how to be compatible.

rob006 commented 5 years ago

Can you show fill stack trace of this error?

rob006 commented 5 years ago

Redis->eval('\r\nlocal hongbao...', 'data1', 'date2', 1, 1, 1533642811, 2)

What is Redis? There is no such class in this extension.

alu12138 commented 5 years ago

{ "name": "Database Exception", "message": "Redis error: ERR value is not an integer or out of range\nRedis command was: EVAL \r\nlocal hongbao_data_key = KEYS[1];\r\nlocal hongbao_receive_key = KEYS[2];\r\nlocal hongbao_receive_list_key = KEYS[3];\r\nlocal hongbao_update_key = KEYS[4];\r\nlocal userid = ARGV[1];\r\nlocal min = tonumber(ARGV[2]);\r\nlocal time = ARGV[3]; hongbao:1:data hongbao:1:set hongbao:1:list hongbao:update 1 1 1533643473 4", "code": 0, "type": "yii\db\Exception", "file": "/test/vendor/yiisoft/yii2-redis/src/Connection.php", "line": 729, "stack-trace": [ "#0 /test/vendor/yiisoft/yii2-redis/src/Connection.php(706): yii\redis\Connection->parseResponse('EVAL \r\nlocal ho...')", "#1 /test/vendor/yiisoft/yii2-redis/src/Connection.php(690): yii\redis\Connection->sendCommandInternal('*10\r\n$4\r\nEVAL\r\n...', Array)", "#2 /test/vendor/yiisoft/yii2-redis/src/Connection.php(630): yii\redis\Connection->executeCommand('EVAL', Array)", "#3 /test/frontend/models/Message.php(277): yii\redis\Connection->__call('eval', Array)", "#4 /test/frontend/models/Message.php(277): yii\redis\Connection->eval('\r\nlocal hongbao...', 'hongbao:1:data', 'hongbao:1:set', 'hongbao:1:list', 'hongbao:update', 1, 1, 1533643473, 4)", "#5 /test/frontend/controllers/v1/MessageController.php(505): frontend\models\Message::openRedisMsg('\r\nlocal hongbao...', Array)", "#6 /test/frontend/controllers/v1/MessageController.php(201): frontend\controllers\v1\MessageController->openUserMsg('1', 1)", "#7 [internal function]: frontend\controllers\v1\MessageController->actionOpen()", "#8 /test/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)", "#9 /test/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)", "#10 /test/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('open', Array)", "#11 /test/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('v1/message/open', Array)", "#12 /test/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))", "#13 /test/frontend/web/index.php(17): yii\base\Application->run()", "#14 {main}" ], "error-info": [] }

muniter commented 1 year ago

Fixed this by using the default redis database 0