<?PHP/*database Tables (' usr_id ', ' name ', ' Face_score ', ' usr_sex ', ' Usr_headi Mgurl '*/ $redis=NewRedis (); $redis->connect (' 127.0.0.1 ', 6379); $usr _id= ' 2007 '; //example One//constructs a JSON string, which is stored in Redis and then read out, where the key is ' MyKey '. $usr _id into a string $ret; $redis->set (' MyKey ').$usr _id, ' [{' usr_id ': ' + ', ' name ': ' Qipeng ', ' usr_sex ': ' 1 ', ' face_score ': ' + ', ' usr_headimgurl ': ' http://aaa '}] ');//Note that key value is a double-quote if($ret=$redis->get (' MyKey ').$usr _id)) { //echo $ret; $row= Json_decode ($ret,true); $usr _id=$row[0] [' usr_id ']; $name=$row[0] [' Name ']; $usr _sex=$row[0] [' Usr_sex ']; $face _score=$row[0] [' Face_score ']; $usr _headimgurl=stripslashes($row[0] [' Usr_headimgurl ']); Echo"\ r \ n UserID:$usr _id, Wxname:$name, Sex:$usr _sex, Face_score:$face _scoreUsr_headimgurl:$usr _headimgurl\ n "; } //Method Example two//through an array to construct a JSON string, into Redis, where these values can be read from the database $get _data[] =Array(' usr_id ' = ' + ', ' name ' = ' Qipeng ', ' face_score ' = ' + ', ' usr_sex ' = ' 1 ', ' Usr_headimgurl ' = ' http://aaa ' ); $data= Json_encode ($get _data); //echo $data; $redis->set (' MyKey ').$usr _id,$data); if($ret=$redis->get (' MyKey ').$usr _id)) { $row= Json_decode ($ret,true); //Var_dump ($row); $usr _id=$row[0] [' usr_id ']; $name=$row[0] [' Name ']; $usr _sex=$row[0] [' Usr_sex ']; $face _score=$row[0] [' Face_score ']; $usr _headimgurl=stripslashes($row[0] [' Usr_headimgurl ']); Echo"\ r \ n UserID:$usr _id, Wxname:$name, Sex:$usr _sex, Face_score:$face _scoreUsr_headimgurl:$usr _headimgurl\ n "; }?>
Redis does database caching PHP implementation