优化代码

main
gzydong 2021-06-04 19:55:20 +08:00
parent c99b294edd
commit d93ec44d5c
3 changed files with 33 additions and 13 deletions

View File

@ -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 连接
*

View File

@ -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());
}
}

View File

@ -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()
{
}
}