CodeIgniter,使用Redis作為會話管理器

[英]CodeIgniter, Using Redis as session manager


From github the configuration claims that I need to set

從github配置聲稱我需要設置

$config['sess_use_database'] = TRUE;

This is required to store the session data in redis.

這是將會話數據存儲在redis中所必需的。

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

但是,從CodeIgniter的指南中如果$ config ['sess_use_database'] = TRUE;會話類將會話數據存儲在DB中。

I want to understand, how the database write is bypassed even if we set 'sess_use_database' config to true.

我想了解,即使我們將'sess_use_database'配置為true,也會繞過數據庫寫入。

Secondly, the method requires phpredis extension to be installed.

其次,該方法需要安裝phpredis擴展。

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

我已經從以下github存儲庫安裝了另一個CI redis庫。

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

有人可以幫我配置ericterpstra的代碼,[文件名:ci_sock / part_two / MY_Session.php]這樣它可以使用上面的庫而不是phpredis嗎?

2 个解决方案

#1


1  

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

如果我沒弄錯的話,phpredis是PHP的C擴展,其中CI redis庫是redis客戶端的純PHP實現。您可能已將phpredis安裝為擴展並仍然使用CI redis庫(盡管您可能希望將其轉儲,因為它不再維護)。

If you do install phpredis you can bypass the whole CodeIgnitor session configuration issue by just switching the default session handler in your php.ini file to use redis.

如果您確實安裝了phpredis,只需切換php.ini文件中的默認會話處理程序即可繞過整個CodeIgnitor會話配置問題以使用redis。

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

以下是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 to store sessions.

這將透明地使用您的redis存儲來存儲會話。

#2


0  

Redis session is supported in Codeigniter version 3

Codeigniter版本3支持Redis會話

Edit config file

編輯配置文件

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

Official Documentation Redis Driver

官方文檔Redis驅動程序


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2013/06/10/72a063a01d771d3aabb6bc7daae9fe52.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com