Of course, to write the first installation of PHP extensions, can refer to this article: Redis and PHP Extended installation
Modify the php.ini settings
Copy Code code as follows:
Session.save_handler = Redis
Session.save_path = "Tcp://127.0.0.1:6379″
Reboot php-fpm or Nginx,phpinfo () after modification
Session Redis
If you don't want to modify php.ini,
Copy Code code as follows:
Ini_set ("Session.save_handler", "Redis");
Ini_set ("Session.save_path", "Tcp://127.0.0.1:6379″");
If the configuration file/etc/redis.conf set the connection password Requirepass save session will be an error, Save_path this write tcp://127.0.0.1:6379?auth=authpwd can.
Some netizens mentioned that the Session,redis of file storage or Memcache storage session value will have concurrency consistency problem, this piece has not been carefully measured.
Copy Code code as follows:
<?php
If not modified php.ini the following two lines of comments are removed
Ini_set (' Session.save_handler ', ' Redis ');
Ini_set (' Session.save_path ', ' tcp://127.0.0.1:6379 ');
Session_Start ();
$_session[' sessionid '] = ' This are session content! ';
echo $_session[' SessionID '];
Echo ' <br/> ';
$redis = new Redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Redis with session_id as key and is stored as string
echo $redis->get (' phpredis_session: '. session_id ());
?>