1

I have setup my Laravel application with docker, one container is dedicated to the app one for redis.

I have setup Laravel to use Redis for session an caching.

All works fine but if I enter my Redis container and try to list all keys like:

 $redis-cli
 #KEYS *

It will return only key values used for caching not the session keys.

The above is a doublecheck because actually from Laravel application I set session key and then dump like

 <?php dump(session()->all()); dump(Session::getDefaultDriver()); ?>

and from the dump everything looks fine. I see my session keys and values data structures. Session::getDefaultDriver() //returns "redis"

So, by seeing Cache key:values inside redis container I assume that there's not a connection/docker container issues... Laravel is writing in the correct place. Redis default connection is shared by Cache and SEssion.

In database.php I have:

'redis' => [
'client' => 'predis',
'default' => [
    'host' => env('REDIS_HOST', 'redis'),
    'password' => env('REDIS_PASSWORD', null),
    'port' => env('REDIS_PORT', 6379),
    'database' => 0,
],
],

In session.php I have

 'driver' => env('SESSION_DRIVER', 'redis'),
 ...
 'lifetime' => env('SESSION_LIFETIME', 120),

By seeing the dumps returning correct values in Laravel web application I'm assuming session is working properly and points to redis.

What am I missing?

4
  • Can you add the CLIENT LIST output from redis? Also make sure your php app is connected and shows a connection in the same Mar 29, 2018 at 13:55
  • looks like I see only one connection. The one I'm making on commandline from inside the container. Is the connection from laravel web app persistent and should be listed too?
    – koalaok
    Mar 29, 2018 at 14:25
  • 1
    On the redis cli, run the info command. At the end of the output should be a # Keyspace section. What does that say?
    – patricus
    Mar 29, 2018 at 14:37
  • # Keyspace db0:keys=2,expires=2,avg_ttl=16440517, I think it's referred to the two keys that I cache : KEYS * returns : KEYS * 1) "wwws_cache:VNMmO5IGsngPBjiUU2yiy5OBAR1pzD3bmY0UY" 2) "www2s_cache:CLIENT_ACCESS_TOKEN" - Still missing the session keys....
    – koalaok
    Mar 29, 2018 at 14:43

1 Answer 1

0

run INFO command on your redis container cli ,at the end of the output is a #Keyspace part which lists your available namespaces on redis , you can switch to every one of them by runnig SELECT command . for example if your keyspaces are :

  • db0:keys=53,expires=43,avg_ttl=95982529
  • db1:keys=5,expires=2,avg_ttl=15614644950 you can switch to second one by running SELECT 1 after switching to each keyspace run keys * to see what is stored under that keyspace

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.