Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yii-bot opened this issue Aug 6, 2018 · 8 comments
Open

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

yii-bot opened this issue Aug 6, 2018 · 8 comments
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@yii-bot
Copy link

yii-bot commented Aug 6, 2018

This issue has originally been reported by @alu12138 at yiisoft/yii2#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
Copy link

alu12138 commented Aug 7, 2018

Yii version 2.0.15.1

@rob006
Copy link
Contributor

rob006 commented Aug 7, 2018

You should pass arguments separately instead of using array.

$redis->eval($lua, "data1", "date2", 1, 1, time(), 2);

@rob006 rob006 closed this as completed Aug 7, 2018
@alu12138
Copy link

alu12138 commented Aug 7, 2018

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

@alu12138
Copy link

alu12138 commented Aug 7, 2018

这个问题是,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
Copy link
Contributor

rob006 commented Aug 7, 2018

Can you show fill stack trace of this error?

@rob006 rob006 reopened this Aug 7, 2018
@rob006
Copy link
Contributor

rob006 commented Aug 7, 2018

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

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

@yiisoft yiisoft deleted a comment from yii-bot Aug 7, 2018
@alu12138
Copy link

alu12138 commented Aug 7, 2018

{
"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": []
}

@bizley bizley added the status:to be verified Needs to be reproduced and validated. label Jun 17, 2021
@muniter
Copy link

muniter commented Dec 8, 2022

Fixed this by using the default redis database 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

6 participants