Of course, you need to install the php extension first. You can refer to this article: Redis and PHP extension installation
Modify the settings of php.ini
Copy the code The code is as follows:
session.save_handler = redis
session.save_path = “tcp://127.0.0.1:6379″
After modification, restart php-fpm or nginx, phpinfo ()
session redis
If you don’t want to modify php.ini, you can do this
Copy the code The code is as follows:
ini_set( "session.save_handler","redis");
ini_set("session.save_path","tcp://127.0.0.1:6379");
If the configuration file /etc/ If the connection password requirepass is set in redis.conf, an error will be reported when saving the session. In save_path, write tcp://127.0.0.1:6379?auth=authpwd.
Some netizens mentioned that compared to file storage sessions, redis or memcache will have concurrency consistency issues when storing session values. This has not been tested in detail.
Copy code The code is as follows:
//If the following two lines of php.ini are not modified Remove the comments
//ini_set('session.save_handler', 'redis');
//ini_set('session.save_path', 'tcp://127.0.0.1:6379');
session_start ();
$_SESSION['sessionid'] = 'this is session content!';
echo $_SESSION['sessionid'];
echo '
';
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
//redis uses session_id as the key and is stored in the form of string
echo $redis->get('PHPREDIS_SESSION:' . session_id());
?>
http://www.bkjia.com/PHPjc/825000.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825000.htmlTechArticleOf course, you need to install the php extension first. You can refer to this article: Redis and PHP extension installation and modification php.ini The setting copy code is as follows: session.save_handler = redis session.save_path...