Is it perhaps cached to use file? php artisan config:clear
Sep 21, 2022
4
Level 6
Redis Facade cannot get session data
I set the session driver to redis, but I don't get session data from Redis Facade.
This is config/session.php
'driver' => env('SESSION_DRIVER', 'file'),
'connection' => env('SESSION_CONNECTION'),
This is .env
SESSION_DRIVER=redis
SESSION_CONNECTION="session-connection"
This is config/database.php
'redis' => [
'session-connection' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
'prefix' => 'session:',
],
],
These are codes which run in the php artisan tinker:
>>> session(['key'=>'value']);
=> null
>>> session('key');
=> "value"
>>> use Illuminate\Support\Facades\Redis;
>>> Redis::connection('session-connection')->get('key')
=> null
>>> Redis::connection('session-connection')->keys('*')
=> []
But Redis Facade can get Cache data, and I don't know why session cannot.
These are settings related to the cache.
This is config/cache.php
'default' => env('CACHE_DRIVER', 'file'),
'stores' => [
'redis' => [
'driver' => 'redis',
'connection' => 'cache-connection',
'lock_connection' => 'cache-lock',
],
],
//'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
This is .env
CACHE_DRIVER=redis
This is config/database.php
'redis' => [
'cache-connection' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => env('REDIS_DB', '0'),
'prefix' => 'cache:',
],
'cache-lock' => [
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'username' => env('REDIS_USERNAME'),
'password' => env('REDIS_PASSWORD'),
'port' => env('REDIS_PORT', '6379'),
'database' => '1',
'prefix' => 'cache-lock:',
],
],
These are codes which run in the php artisan tinker:
>>> Cache::set('cachekey',1);
=> true
>>> Cache::get('cachekey');
=> "1"
>>> use Illuminate\Support\Facades\Redis;
>>> Redis::connection('cache-connection')->get('cachekey')
=> "1"
>>> Redis::connection('cache-connection')->keys('*')
=> [
"cache:cachekey",
]
Any ideas? Thank you!
Please or to participate in this conversation.