: This article mainly introduces the phpRedis storage Session. if you are interested in the PHP Tutorial, refer to it. More please support: http://www.webyang.net/Html/web/article_180.html
Redis is a high-performance key-value database. The emergence of redis can play a good complementary role in relational databases in some cases. On the other hand, many users choose redis for session storage. It makes up for the speed and benefits of file storage to achieve a higher availability.
Modify php. ini settings
- session.save_handler = redis
- session.save_path ="tcp://127.0.0.1:6379"
After modification, restart php-fpm. phpinfo () can view that the session is stored in redis.
If you do not want to modify php. ini, add the following to the code:
- ini_set("session.save_handler","redis");
- ini_set("session.save_path","tcp://127.0.0.1:6379");
If the connection password (
RequirePass), the save_path of the session needs to be modified to: tcp: // 127.0.0.1: 6379? Auth =
RequireThe value of pass.
If you select redis database, session. save_path = "tcp: // xx. xx: 6789? Database = 11 ", and so on.
View the redis stored session value:
-
- Session_start ();
- $ _ SESSION ['sessionid'] = 'www .webyang.net ';
-
- $ Redis = new redis ();
- $ Redis-> connect ('2017. 0.0.1 ', 127 );
- // Redis uses PHPREDIS_SESSION: adds session_id as the key and stores it as a string
- Echo $ redis-> get ('phpredis _ SESSION: '. session_id (); // output www.webyang.net
- ?>
On the Internet, we can see that there is a question about the concurrency consistency of the redis stored session value (the file storage session has a file lock for processing). This is not studied.
Install the redis service and php redis extension in linux: www.webyang.net/Html/web/article_174.html
The above introduces the php Redis storage Session, including The require content, hope to be helpful to friends who are interested in the PHP Tutorial.