Yii2 RBAC Redis-怎么了?

时间:2019-02-25 14:57:49

标签: redis yii2 yii2-advanced-app rbac yii2-rbac

我尝试在Yii2高级应用程序( sweelix / yii2-redis-rbac yiisoft / yii2-redis 中使用 RBAC 已安装。)

  1. common / main.php:

    //....
    'components' => [
        'authManager' => [
            'class' => 'sweelix\rbac\redis\Manager',
            'db' => 'redis',
        ],
        // ...
    ],
    
  2. common / main-local.php:

    //....
    'components' => [
        'authManager' => [
            'class' => 'yii\redis\Connection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 1,
        ],
        // ...
    ],
    
  3. 让我们尝试初始化(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返回:

Error: Redis error: ERR wrong number of arguments for 'hget' command. Redis command was: HGET auth:mappings:rules 

对象转储:

    $user = $auth->createRole('user');
    var_dump($user);die;

返回:

    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 在第 364 行: 如果$ item-> ruleName为null,则出现错误...

$ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);

版本:

Redis server v=3.2.6"yiisoft/yii2": "~2.0.14"yiisoft/yii2-redis 2.0.8PHP 7.0.33

1 个答案:

答案 0 :(得分:0)

我在其他应用程序和环境中对其进行了检查,发现它可以在版本"yiisoft/yii2-redis": "2.0.8"上使用,并且在"yiisoft/yii2-redis": "2.0.9"上可以提供错误信息( sweelix \ rbac \ redisManager 在< strong> 364 : $ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);)。 如果您强制切换到软件包的“ 2.0.8 ”版本,该错误就会消失。