Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
de4b32d0
Commit
de4b32d0
authored
Dec 18, 2018
by
zw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug
parent
96cc912f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
179 additions
and
0 deletions
+179
-0
RedisExt.php
application/index/extra/RedisExt.php
+59
-0
RedisPackage.php
application/index/extra/RedisPackage.php
+106
-0
queue.php
application/index/extra/queue.php
+14
-0
No files found.
application/index/extra/RedisExt.php
0 → 100644
View file @
de4b32d0
<?php
namespace
app\extra
;
use
RedisException
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/4/20
* Time : 13:49
* Intro:
*/
class
RedisExt
{
private
static
$_instance
=
null
;
//静态实例
private
function
__construct
()
{
$config
=
[
'host'
=>
'127.0.0.1'
,
'port'
=>
6379
,
'password'
=>
''
,
'select'
=>
0
,
'timeout'
=>
0
,
'expire'
=>
0
,
'persistent'
=>
false
,
'prefix'
=>
''
,
];
self
::
$_instance
=
new
\Redis
();
try
{
self
::
$_instance
->
connect
(
$config
[
"host"
],
$config
[
"port"
],
$config
[
"timeout"
]
);
}
catch
(
RedisException
$exception
){
throw
new
RedisException
(
$exception
);
}
}
public
static
function
getRedis
()
{
try
{
if
(
!
self
::
$_instance
)
{
new
self
;
}
}
catch
(
RedisException
$exception
)
{
return
false
;
}
return
self
::
$_instance
;
}
}
\ No newline at end of file
application/index/extra/RedisPackage.php
0 → 100644
View file @
de4b32d0
<?php
namespace
app\extra
;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/9
* Time : 15:20
* Intro: redis connect class
*/
class
RedisPackage
{
protected
static
$handler
=
null
;
protected
$options
=
[
'host'
=>
'101.132.186.250'
,
'port'
=>
6379
,
'password'
=>
''
,
'select'
=>
0
,
'timeout'
=>
0
,
'expire'
=>
0
,
'persistent'
=>
false
,
'prefix'
=>
''
,
];
public
function
__construct
(
$options
=
[])
{
if
(
!
extension_loaded
(
'redis'
))
{
//判断是否有扩展(如果你的apache没reids扩展就会抛出这个异常)
throw
new
\BadFunctionCallException
(
'not support: redis'
);
}
if
(
!
empty
(
$options
))
{
$this
->
options
=
array_merge
(
$this
->
options
,
$options
);
}
$func
=
$this
->
options
[
'persistent'
]
?
'pconnect'
:
'connect'
;
//判断是否长连接
self
::
$handler
=
new
\Redis
;
self
::
$handler
->
$func
(
$this
->
options
[
'host'
],
$this
->
options
[
'port'
],
$this
->
options
[
'timeout'
]);
if
(
''
!=
$this
->
options
[
'password'
])
{
self
::
$handler
->
auth
(
$this
->
options
[
'password'
]);
}
if
(
0
!=
$this
->
options
[
'select'
])
{
self
::
$handler
->
select
(
$this
->
options
[
'select'
]);
}
}
/**
* 写入缓存
* @param string $key 键名
* @param string $value 键值
* @param int $exprie 过期时间 0:永不过期
* @return bool
*/
public
static
function
set
(
$key
,
$value
,
$exprie
=
0
)
{
if
(
$exprie
==
0
)
{
$set
=
self
::
$handler
->
set
(
$key
,
$value
);
}
else
{
$set
=
self
::
$handler
->
setex
(
$key
,
$exprie
,
$value
);
}
return
$set
;
}
/**
* 读取缓存
* @param string $key 键值
* @return mixed
*/
public
static
function
get
(
$key
)
{
$fun
=
is_array
(
$key
)
?
'Mget'
:
'get'
;
return
self
::
$handler
->
{
$fun
}(
$key
);
}
/**
* 获取值长度
* @param string $key
* @return int
*/
public
static
function
lLen
(
$key
)
{
return
self
::
$handler
->
lLen
(
$key
);
}
/**
* 将一个或多个值插入到列表头部
* @param $key
* @param $value
* @return int
*/
public
static
function
LPush
(
$key
,
$value
,
$value2
=
null
,
$valueN
=
null
)
{
return
self
::
$handler
->
lPush
(
$key
,
$value
,
$value2
,
$valueN
);
}
/**
* 移出并获取列表的第一个元素
* @param string $key
* @return string
*/
public
static
function
lPop
(
$key
)
{
return
self
::
$handler
->
lPop
(
$key
);
}
}
\ No newline at end of file
application/index/extra/queue.php
0 → 100755
View file @
de4b32d0
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
return
[
'connector'
=>
'Sync'
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment