CodeIgniter Forums
Session/Redis question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Session/Redis question (/showthread.php?tid=72340)



Session/Redis question - NiteRaven - 12-06-2018

If I'm using redis for sessions and I store some session data in variables for 'user' (active user data) and 'business' (active business) and then I get those session variables with:

$session->get('user');
$session->get('business');

Is that making two calls for the redis server?

Am I better off doing:

$data = $session->get();

$data['user'];
$data['business'];

Is that one call?

I'm running my application on the Google Cloud. I'm obviously trying to reduce calls to the redis server and can't see those calls like database calls in the debug bar. That would be sweet if I could... but not necessary if I knew what is happening.

Bonus question, the session docs mention data will be stored in $_SESSION superglobal. Is that true for redis?

Thanks in advance!


RE: Session/Redis question - dave friend - 12-07-2018

Redis is used to persist the session data. The default behavior is that session data is read from the persistent source into $_SESSION when the session starts. $_SESSION is written to the persistent source when the script ends or the session is otherwise ended, i.e. with session_write_close().

So, the two get() calls are not making any calls to the redis server.

The get calls you make are literally returning $_SESSION['user'] and $_SESSION['business']