Reputation: 101
I want to store the session to redis in Laravel.
I was do :
- Change the session driver into 'redis'
- Set my redis server
- and then use this code to store $req->session()->put($email, json_encode($user));
The code was run successfully. And it was store to redis. But, I just simply add the code to 1 function.
Why the other function like example testing()/check(), also setex to redis? I don't even put the code into that function.
Upvotes: 1
Views: 2165
Reputation: 9371
You can just set the session driver
to redis (in your .env file) and use
session(['key', $val]);
to store session values
and
session('key');
to retrieve them
Upvotes: 1
Reputation: 4248
You can store data in Redis this way :-
use Illuminate\Support\Facades\Redis; // add in top of controler before class
or
use Redis;
//put this in function
$redis = new Redis();
$redis->set('boo','Have beer and relax!')
$redis->get('boo');
Upvotes: 0