CodeIgniter using Redis as a session manager

From github , the configuration claims that I need to install

$config['sess_use_database'] = TRUE; 

This is necessary to store session data in redis.

However, from CodeIgniter's Guide If $config['sess_use_database'] = TRUE; the session class will store session data in the database.

I want to understand how a database record will work, even if we set config 'sess_use_database' to true.

Secondly, the phpredis extension is required for this method.

I already have another CI redis library installed from the following github repository .

Can someone help me customize the code from ericterpstra, [File name: ci_sock / part_two / MY_Session.php] so that it can use the above library instead of phpredis?

+4
source share
2 answers

If I'm not mistaken, phpredis is a C extension for PHP, where the CI redis library is a pure implementation of the redis PHP client. You may have phpredis installed as an extension and still use your CI redis library (although you might want to drop it because it is no longer supported).

If you install phpredis , you can get around the entire CodeIgnitor session configuration problem by simply switching the default session handler to your php.ini file to use redis.

Here is an example from https://github.com/phpredis/phpredis#php-session-handler :

 session.save_handler = redis session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2" 

This will transparently use your redis storage for session storage.

+1
source

Redis session supported by Codeigniter version 3

Change configuration file

 $config['sess_driver'] = 'redis'; //enable redis session $config['sess_save_path'] = 'tcp://localhost:6379'; // redis hostname:port 

White Paper Redis Driver

0
source

Source: https://habr.com/ru/post/1485409/


All Articles