This article introduces the content is about Php-redis session operation, has certain reference value, now shares to everybody, has the need friend can refer to
Configure PHP
First configure PHP parameters, the following 2 methods
Method 1:
Modify the php.ini file directly
Session.save_handler = Redissession.save_path = "tcp://127.0.0.1:6379"
Method 2:
Add the following to the header of the code page:
Ini_set ("Session.save_handler", "Redis"), Ini_set ("Session.save_path", "tcp://127.0.0.1:6379");
Note: If redis.conf
the password is set in the configuration file Requirepass,save_path need to write this tcp://127.0.0.1:6379?auth=authpwd
, otherwise can not error and will error
Page testing
<?php//ini_set ("Session.save_handler", "Redis"),//ini_set ("Session.save_path", "TCP ://127.0.0.1:6379 "); Session_Start ();//Deposit session$_session[' class '] = Array (' name ' = ' = ' alicelock ', ' num ' = 21); /Connection Redis$redis = new Redis (), $redis->connect (' 127.0.0.1 ', 6379);//Check Session_idecho ' session_id: '. SESSION_ID (). ' <br/> ';//redis deposited session (Redis is stored as a string as a key, session_id) echo ' redis_session: '. $redis->get (' phpredis_session: '. session_id ()). ' <br/> ';//php gets the session value Echo ' Php_session: '. Json_encode ($_session[' class ');