Redis applications in projects ps:php automatically turn off Redis connections do not require manual shutdown for temporary data can be redis directly from the database
/* Message Queuing instance/Public function Insertinfo () {//connection local Redis service $redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Store data into the list $infos = Array (' Info1 ' =>, ' Info2 ' => 88);
$redis->lpush ($key, Json_encode ($infos));
Gets the stored data and outputs the $arList = $redis->lrange ("Tutorial-list", 0, 30);
Print_r ($arList);
Exit ();
/* Read instance//Public function GetInfo () {//Connect local Redis Service $redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Gets the stored data and outputs $result = Json_decode ($redis->get ("Tutoriallist"), ' true ';
if (empty ($result)) {$sql = "select * from Mobantestinfo";
$VModel = new Huanshanvotemodel ();
$result = $VModel->query ($sql);
Re-put the cache into the database Redis cannot directly save the array needs to be converted to JSON $redis->set (Json_encode ($result));
}else{//Connect the local Redis service $redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Gets the stored data and outputs $result = Json_decode ($redis->get ("Tutoriallist"), ' true ';
} print_r ($result); Exit (); }
/* Update instance *
/Public Function Updateinfo () {
//Run SQL statement
$sql = "Update mobantestinfo set info1=1 where id=40";
$VModel = new Huanshanvotemodel ();
$isOk = $VModel->execute ($sql);
Connect the local Redis service
$redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
/* Delete key*/
$redis->del (' tutoriallist ');
}
/* Delete instance *
/Public Function Deleteinfo () {
//Run SQL statement
$sql = "Delete from mobantestinfo where id=40";
$VModel = new Huanshanvotemodel ();
$isOk = $VModel->execute ($sql);
Connect the local Redis service
$redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
$redis->del (' tutoriallist ');
}
The above is small series for everyone to bring the Redis in the project application of all content, I hope that we support cloud-Habitat Community ~