Is anyone here?
Feb 19, 2016
1
Level 1
Redis-based Session Option is not working
I wanted to use redis to save users' sessions. So i followed one sample,
<?php
namespace App\Extensions;
use Illuminate\Support\Facades\Redis as Redis;
class RedisSessionStore implements SessionHandlerInterface {
public function open($savePath, $sessionName) {}
public function close() {}
public function read($sessionId) {
$redis = Redis::connection('default');
return $redis->get($sessionId);
}
public function write($sessionId, $data) {
$redis = Redis::connection('default');
$redis->set($sessionId, $data);
}
public function destroy($sessionId) {
$redis = Redis::connection('default');
$redis->command('del', $sessionId);
}
public function gc($lifetime) {
//
}
}
Above file is saved as RedisSessionStore.php and put in Extentions folder under app folder.
<?php
namespace App\Providers;
use Session;
use App\Extensions\RedisSessionStore;
use Illuminate\Support\ServiceProvider;
class SessionServiceProvider extends ServiceProvider {
public function boot() {
Session::extend('redis', function($app) {
return new RedisSessionStore;
});
}
public function register() {}
}
Above file is saved as SessionServiceProvider.php and put in Providers folder under app folder.
I have added App\Providers\SessionServiceProvider::class, into Providers in app/config/app.php file. And i have also changed the 'driver' => env('SESSION_DRIVER', 'file'), to 'driver' => env('SESSION_DRIVER', 'redis'),in app\config\session.php.
But in fact it was still saving the session into file...Can anyone help me out?
Please or to participate in this conversation.