【问题标题】:Yii2 RBAC Redis - whats wrong?Yii2 RBAC Redis - 怎么了?
【发布时间】:2019-02-25 14:57:48
【问题描述】:

我正在尝试在我的 Yii2 高级应用程序中使用 RBACsweelix/yii2-redis-rbacyiisoft/yii2-redis已安装)。

  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.8, PHP 7.0.33

【问题讨论】:

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


    【解决方案1】:

    我在其他应用程序和环境中检查了它,发现它适用于版本 "yiisoft/yii2-redis": "2.0.8""yiisoft/yii2-redis": "2.0.9" 它给出了错误(sweelix\rbac\redisManager 在行 364: $ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);)。 如果你强行切换到包的“2.0.8”版本,错误就会消失。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-09
      • 2016-08-26
      • 2015-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多