diff --git a/app/Cache/Repository/AbstractRedis.php b/app/Cache/Repository/AbstractRedis.php index 6bf1eab..e627a53 100644 --- a/app/Cache/Repository/AbstractRedis.php +++ b/app/Cache/Repository/AbstractRedis.php @@ -2,17 +2,19 @@ namespace App\Cache\Repository; -use App\Traits\StaticInstance; use Hyperf\Redis\Redis; abstract class AbstractRedis { - use StaticInstance; - protected $prefix = 'rds'; protected $name = ''; + public static function getInstance() + { + return container()->get(static::class); + } + /** * 获取 Redis 连接 * diff --git a/app/Command/TestCommand.php b/app/Command/TestCommand.php index 5b06283..57f4a82 100644 --- a/app/Command/TestCommand.php +++ b/app/Command/TestCommand.php @@ -49,7 +49,7 @@ class TestCommand extends HyperfCommand public function handle() { - $lock = LockRedis::getInstance(); + //$lock = LockRedis::getInstance(); //var_dump($lock->delete('ttt')); //var_dump($lock->lock('ttt', 180, 5)); @@ -143,5 +143,31 @@ class TestCommand extends HyperfCommand //SocketFdBindUser::getInstance()->bind(1, 2054); //SocketUserBindFds::getInstance()->bind(1, 2054); + + $model1 = SocketUserBindFds::getInstance(); + $model2 = FriendRemark::getInstance(); + + var_dump($model1 === SocketUserBindFds::getInstance()); + var_dump($model2 === FriendRemark::getInstance()); + + var_dump(SocketUserBindFds::getInstance()); + var_dump(FriendRemark::getInstance()); + + //SocketUserBindFds::getInstance(); + //SocketUserBindFds::getInstance(); + //SocketRoom::getInstance(); + //FriendRemark::getInstance(); + //SocketUserBindFds::getInstance(); + //SocketRoom::getInstance(); + //FriendRemark::getInstance(); + + //var_dump(SocketUserBindFds::getInstance()); + //var_dump(SocketRoom::getInstance()); + //var_dump(FriendRemark::getInstance()); + // + //var_dump('------'); + //var_dump(SocketUserBindFds::getInstance()); + //var_dump(SocketRoom::getInstance()); + //var_dump(FriendRemark::getInstance()); } } diff --git a/app/Traits/StaticInstance.php b/app/Traits/StaticInstance.php index 872b30e..98c2a93 100644 --- a/app/Traits/StaticInstance.php +++ b/app/Traits/StaticInstance.php @@ -11,10 +11,6 @@ trait StaticInstance { private static $instance; - private function __construct() - { - } - /** * 获取单例 * @@ -23,13 +19,9 @@ trait StaticInstance static public function getInstance() { if (is_null(static::$instance)) { - static::$instance = new static; + static::$instance = new static(); } return static::$instance; } - - private function __clone() - { - } }