<p>Apparently, the namePrefix is only included <em>before</em> it is MD5 hashed, meaning that the redis cache key will not include it.</p>
<p>You can apparently configure it with the redis keyPrefix like this</p>
<pre><code>'mutex' =&gt; [
    'mutex' =&gt; [
        'class' =&gt; 'yii\redis\Mutex',
        'keyPrefix' =&gt; 'mutex_',
    ],
],
</code></pre>
<p>See <a href="https://github.com/craftcms/cms/issues/12181" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/12181</a></p>

CC BY-SA 4.0
2022-10-25T18:45:37.227Z
2022-10-25T18:45:37.227Z
jishi
<p>I have setup redis and redis mutex for a multi-container setup.</p>
<pre><code>'mutex' =&gt; [
    'mutex' =&gt; 'yii\redis\Mutex',
    'namePrefix' =&gt; 'mutex_',
],
</code></pre>
<p>It works, I can see the mutex keys popup occasionally, however the namePrefix seems to do nothing. I can't use the keyPrefix from the yii\redis\Mutex since this is some sort of derived class...?</p>
<p>Reading the documentation for namePrefix (<a href="https://docs.craftcms.com/api/v4/craft-mutex-mutextrait.html#public-properties" rel="nofollow noreferrer">https://docs.craftcms.com/api/v4/craft-mutex-mutextrait.html#public-properties</a>) this is exactly how I interpret it, however it doesn't seem to stick.</p>
<p>I'm sending sessions to redis as well, with</p>
<pre><code>'session' =&gt; [
    'class' =&gt; yii\redis\Session::class,
    'as session' =&gt; craft\behaviors\SessionBehavior::class,
    'keyPrefix' =&gt; 'session_',
],
</code></pre>
<p>And that prefixes the sessions correctly as expected, same with caches.</p>

<redis><mutex>
Key prefix for redis mutex locks?
# Key prefix for redis mutex locks?

(Asked by: username_0 on 2022-10-24)

I have setup redis and redis mutex for a multi-container setup.
'mutex' => [
    'mutex' => 'yii\redis\Mutex',
    'namePrefix' => 'mutex_',
],

It works, I can see the mutex keys popup occasionally, however the namePrefix seems to do nothing. I can't use the keyPrefix from the yii\redis\Mutex since this is some sort of derived class...?
Reading the documentation for namePrefix (https://docs.craftcms.com/api/v4/craft-mutex-mutextrait.html#public-properties) this is exactly how I interpret it, however it doesn't seem to stick.
I'm sending sessions to redis as well, with
'session' => [
    'class' => yii\redis\Session::class,
    'as session' => craft\behaviors\SessionBehavior::class,
    'keyPrefix' => 'session_',
],

And that prefixes the sessions correctly as expected, same with caches.

**Tags:** redis, mutex


---

## 1 answers

### Answer by username_0 on 2022-10-25. Score: 1

Apparently, the namePrefix is only included before it is MD5 hashed, meaning that the redis cache key will not include it.
You can apparently configure it with the redis keyPrefix like this
'mutex' => [
    'mutex' => [
        'class' => 'yii\redis\Mutex',
        'keyPrefix' => 'mutex_',
    ],
],

See https://github.com/craftcms/cms/issues/12181


---

