Skip to content

Commit

Permalink
支持ThinkPHP6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
edward1108 committed Oct 30, 2020
1 parent ba67d55 commit 14024a5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# edward-redis
ThinkPHP框架的Redis扩展,支持多种Redis使用方法。支持ThinkPHP5.0和ThinkPHP5.1
ThinkPHP框架的Redis扩展,支持多种Redis使用方法。支持ThinkPHP6.0和ThinkPHP5.x

## 安装
> composer require edward1108/edward-redis
## 配置
tp5.0

ThinkPHP6.0.x 和 ThinkPHP5.1.x
```
config.php
'redis' => [
config/redis.php
return [
'host' => '127.0.0.1', // redis主机
'port' => '', // redis端口
'password' => '', // 密码
Expand All @@ -17,13 +18,13 @@ config.php
'timeout' => 0, // 超时时间(秒)
'persistent' => true, // 是否长连接
'prefix' => '', //前缀
]
];
```

tp5.1
ThinkPHP5.0.x
```
config/redis.php
return [
config.php
'redis' => [
'host' => '127.0.0.1', // redis主机
'port' => '', // redis端口
'password' => '', // 密码
Expand All @@ -32,7 +33,7 @@ return [
'timeout' => 0, // 超时时间(秒)
'persistent' => true, // 是否长连接
'prefix' => '', //前缀
];
]
```

## 例子
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edward1108/edward-redis",
"description": "ThinkPHP框架的Redis扩展,支持多种Redis使用方法。支持ThinkPHP5.0和ThinkPHP5.1",
"description": "ThinkPHP框架的Redis扩展,支持多种Redis使用方法。支持ThinkPHP6.0和ThinkPHP5.x",
"keywords": [
"Redis",
"ThinkPHP",
Expand All @@ -9,7 +9,7 @@
],
"type": "project",
"require": {
"php": ">=5.6.0"
"php": ">=7.1.0"
},
"homepage": "https://github.com/Edward1108/edward-redis",
"license": "MIT",
Expand All @@ -23,5 +23,12 @@
"psr-4" : {
"edward\\redis\\" : "src"
}
},
"extra":{
"think": {
"config":{
"redis": "src/config.php"
}
}
}
}
4 changes: 3 additions & 1 deletion src/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ class Redis
*/
private static function init(){
if(defined('THINK_VERSION')) {
//ThinkPHP5.0
self::$config = array_merge(self::$config, \think\Config::get('redis'));
} else {
self::$config = array_merge(self::$config, \think\facade\Config::pull('redis'));
//ThinkPHP5.1 和 ThinkPHP6.0
self::$config = array_merge(self::$config, \think\facade\Config::get('redis'));
}
if( is_null(self::$handler) ) {
$class = '\\edward\\redis\\driver\\RedisDriver'; //此处部署Redis驱动所在位置,本例为org/redis/driver/Redis,实际根据位置修改
Expand Down
15 changes: 15 additions & 0 deletions src/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
// +----------------------------------------------------------------------
// | Captcha配置文件
// +----------------------------------------------------------------------

return [
'host' => '127.0.0.1', // redis主机
'port' => '', // redis端口
'password' => '', // 密码
'select' => 0, // 操作库
'expire' => 0, // 有效期(秒)
'timeout' => 0, // 超时时间(秒)
'persistent' => true, // 是否长连接
'prefix' => '', //前缀
];

0 comments on commit 14024a5

Please sign in to comment.