I`m tryind to use RBAC in my Yii2 advanced app (sweelix/yii2-redis-rbac and yiisoft/yii2-redis is installed).
common/main.php:
//.... 'components' => [ 'authManager' => [ 'class' => 'sweelix\rbac\redis\Manager', 'db' => 'redis', ], // ... ],common/main-local.php:
//.... 'components' => [ 'authManager' => [ 'class' => 'yii\redis\Connection', 'hostname' => 'localhost', 'port' => 6379, 'database' => 1, ], // ... ],Let`s try to init (RbacController):
public function actionInit() { $auth->removeAll(); $user = $auth->createRole('user'); $auth->add($user); $admin = $auth->createRole('admin'); $auth->add($admin); $auth->addChild($admin, $user); $auth->assign($admin, 1); // 1 - is id of admin user on database }
php yii rbac/init return:
Error: Redis error: ERR wrong number of arguments for 'hget' command. Redis command was: HGET auth:mappings:rules
Dump of object:
$user = $auth->createRole('user');
var_dump($user);die;
returns:
object(yii\rbac\Role)#21 (7) {
["type"]=> int(1)
["name"]=> string(4) "user"
["description"]=> NULL
["ruleName"]=> NULL
["data"]=> NULL
["createdAt"]=> NULL
["updatedAt"]=> NULL
}
sweelix\rbac\redisManager at line 364: If $item->ruleName is null we have error...
$ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);
Vers.:
Redis server v=3.2.6,
"yiisoft/yii2": "~2.0.14",
yiisoft/yii2-redis 2.0.8,
PHP 7.0.33
I checked it in other applications and environments and noticed that it works on version
"yiisoft/yii2-redis": "2.0.8"and on"yiisoft/yii2-redis": "2.0.9"it gives an error (sweelix\rbac\redisManager at line 364:$ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);). If you forcefully switch to the "2.0.8" version of the package the error disappears.