missing functionality from Yii1

In Yii1 one could define ‘hashKey’ => false to disable Yii from MD5-ing the keys when storing data in cache


'cache' => array(                                

            'class' => 'CRedisCache',

            'hostname' => 'localhost', 

            'port' => 6379,

            'database' => 0,

            'hashKey' => false,     // do not MD5 cache keys

            'keyPrefix' => '',

        ), 

This functionality is missing fro Yii2 cache AFAIK

It uses a fixed logic:

Which works ok for key like user123

But my keys are like user:thumb:123

Then it will store it like 1990194bc28ff2bc3040444d5ee735f7 and it’s not very usefull when I use a tool like phpredisadmin for debugging

I can understand that in production it may be more secure but let the developer decide about where he/she wants what.

Is there a simple way to have it?

Extending the yii\redis\ActiveRecord just to replace buildKey() seems an overkill

Thanks

Currently the only way is to extend yii\redis\ActiveRecord.

Sorry for the newbie question: do I need to create a new module ‘myredis’, point to it in the config file and let it extend from yii\redis?

Is there a simpler way to just write a class


myActiveRecord extends yii\redis\ActiveRecord

rewrite the specific method and somehow let the other files in yii-redis use this version?

You can use classmap to replace the class during runtime.

Thank you. I tried creating a file common\utility\MyRedisActiveRecord.php (I’m using the advanced theme)


<?php

namespace common\utility;


use Yii;


/**

 * MyRedisActiveRecord replaces yii\redis\ActiveRecord to override the MD5 redis keys with the raw key.

 */

class MyRedisActiveRecord extends yii\redis\ActiveRecord          //    \yii\redis\ActiveRecord

{

    /**

     * {@inheritdoc}

     */

    public static function buildKey($key)

    {

        return $key;

    }

}

and in common\config\bootstrap.php I’ve added:


// Override redis ActiveRecord class with our class

Yii::$classMap['yii\redis\ActiveRecord'] = '@common/utility/MyRedisActiveRecord.php';

echo yii\redis\ActiveRecord::buildKey('test:key:123');

But it kicks an error which I cannot figure out why:


Fatal error: Class 'Yii\redis\ActiveRecord' not found in ...\common\utility\MyRedisActiveRecord.php on line 9

Any idea?

It errors ‘Yii\redis\ActiveRecord’ with capital Y. Could be the reason.

no, It just depends on


extends \yii\redis\ActiveRecord

or


 extends yii\redis\ActiveRecord

Will it be better to add it as a small change request?

I saw that yii Cache also have a builtKey() method