Skip to content

Commit 143b1ef

Browse files
authored
Merge pull request #37 from teamones-open/dev_weijer
fixed: Module用完redis实列就销毁
2 parents 7ef6f04 + 4b70f47 commit 143b1ef

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/think/RedisHandler.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,27 @@ class RedisHandler
196196
/**
197197
* @return RedisManager
198198
*/
199-
public static function instance()
199+
public static function instance($config)
200200
{
201201
if (empty(static::$_manager)) {
202-
203202
if (class_exists('\support\bootstrap\Redis') && isset(\support\bootstrap\Redis::$_manager)) {
204203
// 外面配置了redis 句柄直接获取
205204
static::$_manager = \support\bootstrap\Redis::$_manager;
206205
} else {
207-
$config = config('redis');
208206
static::$_manager = new RedisManager(null, 'phpredis', $config);
209207
}
210208
}
211209
return static::$_manager;
212210
}
213211

212+
/**
213+
* 销毁实列
214+
*/
215+
public static function destroy()
216+
{
217+
static::$_manager = null;
218+
}
219+
214220
/**
215221
* @param $name
216222
* @param $arguments

src/think/cache/driver/Redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($options = [])
3737
];
3838

3939
// 初始化对象
40-
RedisHandler::instance();
40+
RedisHandler::instance($config);
4141
}
4242

4343
/**

src/think/module/Module.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use think\Db;
1515
use think\exception\ErrorCode;
16+
use think\RedisHandler;
1617

1718
class Module
1819
{
@@ -172,9 +173,11 @@ public static function checkSchema()
172173
unset($tempDb);
173174

174175
// 清除数据表字段缓存
176+
RedisHandler::instance(config('redis'));
175177
foreach ($tables as $tableName){
176178
S('fields_' . strtolower($tableName), null);
177179
}
180+
RedisHandler::destroy();
178181
} else {
179182
throw new \RuntimeException('Data structure error. Need module ' . join(',', self::$requireModules), ErrorCode::DATA_STRUCTURE_NEED_MODULE);
180183
}

0 commit comments

Comments
 (0)