Answer the question
In order to leave comments, you need to log in
How to get session key for Redis in YII2?
I've been trying to get the correct session key for an hour, tell me where I'm missing something?
There is a config:
'session' => [
'class' => 'yii\redis\Session',
'redis' => 'redis',
'keyPrefix' => 'QAINAR_SESS_',
'timeout' => 3600,
],
echo "<pre>";
echo Yii::$app->session->id . PHP_EOL;
print_r(Yii::$app->session->keyPrefix . md5(json_encode([__CLASS__, Yii::$app->session->id])));
echo PHP_EOL;
print_r(Yii::$app->redis->executeCommand('KEYS QAINAR_SESS_*'));
echo "</pre>";
8878353c8ca97c34021d62279cc7959a
QAINAR_SESS_85584472a3d4ad2bec0984e356079817
Array
(
[0] => QAINAR_SESS_fd4011b394ac47f32666d77e2ecd7e6d
[1] => QAINAR_SESS_e8192112a517f5f3b0e0e56def0aa2ce
)
Yii::$app->session->keyPrefix . md5(json_encode([__CLASS__, Yii::$app->session->id]))
taken from official code /**
* Generates a unique key used for storing session data in cache.
* @param string $id session variable name
* @return string a safe cache key associated with the session variable name
*/
protected function calculateKey($id)
{
return $this->keyPrefix . md5(json_encode([__CLASS__, $id]));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question