Skip to content

Commit

Permalink
单例模式,多个对象共享一块内存区域(实例)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinywan committed Oct 29, 2016
1 parent d876780 commit 7e90b11
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Backend/Home/Controller/DataBaseController.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ public function localhostRedis(){
}

/**
* 单列模式参考连接:http://www.cnblogs.com/hongfei/archive/2012/07/07/2580994.html
* 【官方解释】:
* 如果两个对象是同一个类的实例,且它们有相同的属性和值,则这两个对象相等。类似的规则还适用与用全等符(===)对两个对象的比较。
* http://php.net/manual/zh/oop4.object-comparison.php
* 是否是同一个对象的比较
* 比较结果:
* 【redis1和redis2:是同一个实例--redis1和redis3:是同一个实例--redis2和redis3:是同一个实例--】
* 对象$redis1,$redis2,$redis3实际上都是使用同一个对象实例,访问的都是同一块内存区域
*
*/
public function ObjectCompare()
{
Expand Down Expand Up @@ -98,7 +103,7 @@ public function ObjectCompare()
*/
public function createRedis()
{
$redis = RedisInstance::getInstance();
$redis = RedisInstance::MasterInstance();
$redis->select(1);
$message = [
'type' => 'say',
Expand Down Expand Up @@ -130,7 +135,7 @@ public function executeFunction()
*/
public function getRedisData()
{
$redis = RedisInstance::getInstance();
$redis = RedisInstance::MasterInstance();
$redis->select(1);
$redisInfo = $redis->lRange('message01',0,-1);
var_dump($redisInfo);
Expand Down

0 comments on commit 7e90b11

Please sign in to comment.