Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

flufduck's avatar

Redis as session driver

Got a weird problem when trying to use Redis as the session driver. Using tinker I'm able to query the Redis server and set keys etc. But when I try to access from the web (using sessions) I get the following:

FatalThrowableError in RedisStore.php line 54:
Fatal error: Call to a member function get() on null

in RedisStore.php line 54
at RedisStore->get('45935b607e4b58923f504d210f85454aba5e23c4') in Repository.php line 129
at Repository->get('45935b607e4b58923f504d210f85454aba5e23c4', '') in CacheBasedSessionHandler.php line 58
at CacheBasedSessionHandler->read('45935b607e4b58923f504d210f85454aba5e23c4') in Store.php line 124
at Store->readFromHandler() in Store.php line 108
at Store->loadSession() in Store.php line 92
at Store->start() in StartSession.php line 104
at StartSession->startSession(object(Request)) in StartSession.php line 57
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53

Config: config/cache.php (stock standard):

        'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
        ],

config/database.php:

'redis' => [
        'cluster' => false,
        'default' => [
            'host'     => env('CACHE_HOST','127.0.0.1'),
            'port'     => 6379,
            'database' => 0,
        ],
    ],

config/session.php:

<?php
return [
    'driver' => 'redis',
];

If it makes a difference I'm using an external Redis server. Telnet is successful.

Cheers

0 likes
9 replies
hoopyfrood's avatar

@flufduck Have you managed to solve it? Stuck on the same issue currently and Google is to no avail. Thanks!

jekinney's avatar

I don't think it's picking up your redis connection config for sessions through the database config file.

Try setting your connection array to the proper credentials besides default.

oromero's avatar

Are you still getting this message?...Me too. I think is a bug on the cache or session driver. Maybe is for some scope property. How you solved it?

oromero's avatar

Ok, Is not a bug. I missed the 'connection' key on the config/session.php. Currently I Have this setup:

config/session.php
    'driver' => env('SESSION_DRIVER', 'redis'),
    'connection' => 'default',
config/database.php
        'default' => [
            'host' => env('REDIS_HOST', 'tcp://127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],

And now it works! Hope help some dude.

4 likes
kenske's avatar

Laravel will only write to the session storage when the HTTP request is ending (gets triggered by the kernel terminate() method). The problem is that tinker does not go through the regular HTTP request flow. This means that all session values are stored in memory and then just discarded when you exit.

In your specific case, you weren't really connecting to the Redis cache at all when using tinker, that's why it seemed to work.

Please or to participate in this conversation.