PHP Redis Storage Session

Source: Internet
Author: User
Tags php redis
Please support: http://www.webyang.net/Html/web/article_180.html

Redis is a high-performance Key-value database. The emergence of Redis, in some cases can be a good complement to the relational database. On the other hand, in the session storage, there are also many people choose Redis. It is used to compensate for the speed and efficiency of file storage to achieve a higher availability.

Modify the settings for PHP.ini

 
  
  
  1. Session . = redis
  2. Session . ="tcp://127.0.0.1:6379"
After modification, restart Php-fpm,phpinfo () to see if the session is stored in Redis.
If you do not want to modify php.ini, you can include it in your code:
 
  
  
  1. Ini_set ("Session.save_handler","Redis");
  2. Ini_set ("Session.save_path","tcp://127.0.0.1:6379");
If redis.conf has the connection password set ( requirePASS), the session Save_path need to be modified to: tcp://127.0.0.1:6379?auth= requireThe value of the pass.
If you choose a Redis database, Session.save_path = "tcp://xx.xx.xx.xx:6789?database=11", and so forth.
To view the value of the Redis storage session:
 
  
  
  1. !--? php
  2. session_start ();
  3. $_session [ ' SessionID ' ] = ' Www.webyang.net ' ;
  4. $redis = new redis ();
  5. $redis -> connect ( ' 127.0.0.1 ' , 6379 );
  6. //redis uses phpredis_session: Add session_id as key, and is stored as string
  7. echo $redis -> get ( ' phpredis_session: ' . session_id ()); //Output www.webyang.net
  8. ?

There is a question on the Internet that the Redis storage session value will have concurrency consistency (file store session with file lock to handle), this block does not study.
Linux installation Redis service and PHP redis extension: www.webyang.net/Html/web/article_174.html


The above describes the PHP Redis storage session, including the require aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.