Please support for more: http://www.webyang.net/Html/web/article_180.html
Redis is a high-performance key-value database. The emergence of redis can play a very good supplementary role to relational databases in some situations. On the other hand, many people choose redis for session storage. It compensates for the speed and efficiency of file storage to achieve a higher availability.
Modify the settings of php.ini
<ol> <li value="1"> <span>session</span><span>.</span><span>save_handler </span><span>=</span><span> redis</span> </li> <li> <span>session</span><span>.</span><span>save_path </span><span>=</span><span>"tcp://127.0.0.1:6379"</span> </li> </ol>
<ol> <li value="1"> <span>ini_set</span><span>(</span><span>"session.save_handler"</span><span>,</span><span>"redis"</span><span>);</span> </li> <li> <span>ini_set</span><span>(</span><span>"session.save_path"</span><span>,</span><span>"tcp://127.0.0.1:6379"</span><span>);</span> </li> </ol>
<ol> <li value="1"> <span><?</span><span>php</span></li><li><span>session_start</span><span>();</span></li><li><span>$_SESSION</span><span>[</span><span>'sessionid'</span><span>]</span><span>=</span><span>'www.webyang.net'</span><span>;</span></li><li><span> </span></li><li><span>$redis </span><span>=</span><span>new</span><span> redis</span><span>();</span></li><li><span>$redis</span><span>-></span><span>connect</span><span>(</span><span>'127.0.0.1'</span><span>,</span><span>6379</span><span>);</span> </li> <li><span>//redis用 PHPREDIS_SESSION: 加 session_id 作为key,并且是以string的形式存储</span></li> <li> <span>echo $redis</span><span>-></span><span>get</span><span>(</span><span>'PHPREDIS_SESSION:'</span><span>.</span><span> session_id</span><span>());</span><span>//输出www.webyang.net</span> </li> <li><span>?></span></li> </ol>
I saw on the Internet that some people questioned the concurrency consistency problem of redis storage session value (file storage session is handled by file locks), but there is no research on this.
Linux installation redis service and php redis extension: www.webyang.net/Html/web/article_174.html
The above introduces the PHP Redis storage session, including the require content. I hope it will be helpful to friends who are interested in PHP tutorials.