Database storage is stored in a list of 2 queues 1 are used as message queues to save to data and one is to read data in real time. In Redis
$redis->lpush ($queenkey, Json_encode ($array));
$redis->lpush ($listkey, Json_encode ($array));
/* Message Queue instance * *
Public Function Insertinfo ()
{
$infos = array (' Info1 ' => mt_rand (10,100), ' Info2 ' => Mt_rand (10,100));
$this->insertinfos ($infos, ' tutorial-list ', ' tutoriallist ');
}
Public Function Insertinfos ($array, $queenkey, $listkey)
{
//Connect local Redis service
$redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Store the data in the list
$redis->lpush ($queenkey, Json_encode ($array));
$redis->lpush ($listkey, Json_encode ($array));
Reading logic reads the REDIS data when the Redis key is not read and then writes back to the list
/* Read instance */Public function GetInfo () {$sql = ' select * mobantestinfo ';
$result = $this->getinfos (' tutoriallist ', $sql);
Redis key is not empty direct read Redis if (empty ($result)) {//Connect local Redis Service $redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Gets the stored data and outputs $result = $redis->lrange (' Tutoriallist ', 0,-1);
foreach ($result as $k => $v) {$result [$k]=json_decode ($v, true);
} print_r ($result);
Exit ();
} function Getinfos ($key, $sql) {//Connect local Redis Service $redis = new \redis ();
$redis->connect (' 127.0.0.1 ', 6379);
Gets the stored data $result = $redis->lrange ($key, 0, 1);
if (empty ($result)) {$VModel = new Huanshanvotemodel ();
$result = $VModel->query ($sql); Re-put the cache queue in the database foreach ($result as $k => $v) {//This place is to be inserted from the right to ensure the same as the database order $redis->rpush ($key, JSON
_encode ($v));
} else {$result = 0;
} return $result; }
The above is a small series for you to bring the Phpredis to improve the real-time Message Queuing method (recommended) All content, I hope that we support cloud-Habitat Community ~