Yii2 RBAC Redis - whats wrong?



i`m lyind在我的yii2高级应用中使用 rbac /yii2-redis 已安装)。

  1. common/main.php:

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

    //....
    'components' => [
        'authManager' => [
            'class' => 'yiiredisConnection',
            'hostname' => 'localhost',
            'port' => 6379,
            'database' => 1,
        ],
        // ...
    ],
    
  3. 让我们尝试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返回:

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(yiirbacRole)#21 (7) {
      ["type"]=> int(1)
      ["name"]=> string(4) "user"
      ["description"]=> NULL
      ["ruleName"]=> NULL
      ["data"]=> NULL
      ["createdAt"]=> NULL
      ["updatedAt"]=> NULL
    }

sweelix rbac redismanager in Line 364 :如果$ item-> rulename为null,我们有错误...

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

我在其他应用程序和环境中对其进行了检查,并注意到它在"yiisoft/yii2-redis": "2.0.8"版本上工作,并且在"yiisoft/yii2-redis": "2.0.9"上有错误( Sweelix rbac rbac rbac redismanager 在行 364 $ruleGuid = $this->db->executeCommand('HGET', [$this->getRuleMappingKey(), $item->ruleName]);)。如果您强行切换到" 2.0.8 "软件包的版本,则错误消失了。

最新更新