PHP Operating Redis Foundation Program

Source: Internet
Author: User

redisadd.php page

<?phpheader ("Content-type:text/html;charset=utf-8");//Create a Redis object $redis=new redis (); if (! $redis- Connect (' 127.0.0.1 ', 6379)) {    die ("Connection Failed");} Add a String if ($redis->set (' name ',  ' China ')) {    echo  "Add name ok";} if ($redis->set (' online ',  ')) {    echo  "Add online ok";} Digital self-increment 1$redis->incr (' online ');//Add an array $cities=array (     ' no1 ' = ' Beijing ',      ' no2 ' = ' Shanghai ');//You must serialize the array serialize into a string, otherwise the get will not come out. if ($redis->set (' Cities ',  serialize ($cities))) {    echo  "add cities  OK ";} Add an object class dog{    public  $name;    public  $age;     function __construct ($name, $age) {         $this->name= $name;         $this->age= $age;     }    } $dog =new dog (' Xiaoqiang '), if ($redis->set (' Dog ',  serialize ($dog))) {     echo  "Add dog ok";} $dog 1=new dog (' xiaoqiang1 ', 1); $dog 2=new dog (' Xiaoqiang2 ', 2); $dog 3=new dog (' Xiaoqiang3 ', 3); $dog 4 =new dog (' Xiaoqiang4 ', 4), $dog 5=new dog (' Xiaoqiang5 ', 5), $dog 6=new dog (' Xiaoqiang6 ', 6); $redis- >delete (' dogline ');//Pay attention to serialization before depositing into Redisif ($redis->rpush (' Dogline ',  serialize ($dog))); if ($redis- Rpush (' Dogline ',  serialize ($dog 1))), if ($redis->rpush (' Dogline ',  serialize ($dog 2))), if ($redis Rpush (' Dogline ',  serialize ($dog 3))), if ($redis->rpush (' Dogline ',  serialize ($dog 4))), if ($redis Rpush (' Dogline ',  serialize ($dog 5))), if ($redis->rpush (' Dogline ',  serialize ($dog 6))); >

Redisget.php page

<?phpheader ("Content-type:text/html;charset=utf-8");//Create a Redis object $redis=new redis (); if (! $redis- Connect (' 127.0.0.1 ', 6379)) {    die ("Connection Failed");} Be sure to introduce the definition of the dog class. class dog{    public  $name;    public  $age;     function __construct ($name, $age) {         $this Name= $name;         $this->age= $age;    }     }//Add a string $val= $redis->get (' name '), $val 1= $redis->get (' online '); $val 2=unserialize ($ Redis->get (' cities ')); $val 3=unserialize ($redis->get (' dog '));//Note Be sure to introduce the definition of class Var_dump ($val);echo  ' < Br /> '; Var_dump ($val 1);echo  ' <br /> '; Var_dump ($val 2);echo  ' <br /> ';// Remove Dog All Properties Var_dump ($val 3);echo  ' <br /> ';//Remove Dog name Var_dump ($val 3->name);echo  ' <br / > '; $doglineLen = $redis->lsize (' Dogline '); for ($i =0; $i < $doglineLen; $i + +) {     $mydog = $redis->lindex (' Dogline ', $i);     echo  ' <pre> ';     var_dump (Unserialize ($mydog));//pay attention to deserialization before removing      echo  ' </pre> ';}? >


This article is from the "11400485" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1795088

PHP Operating Redis Foundation Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.