Chandra Putra Wijaya
Chandra Putra Wijaya

Reputation: 101

Laravel store session to redis

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

Answers (2)

online Thomas
online Thomas

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

kunal
kunal

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

Related Questions