-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathredis.php
52 lines (44 loc) · 1.21 KB
/
redis.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* check if can connect redis
* Class RedisInstance
*/
class RedisInstance{
private static $_instance;
private static $_connectSource;
private function __construct(){
}
/**
* init redis
* @return mixed
* @author deng (2019/9/4 17:52)
*/
public static function getInstance(){
if (!(static::$_instance instanceof \Redis)) {
static::$_instance = new \Redis();
self::getInstance()->connect('127.0.0.1', 6379, 9000);
}
return static::$_instance;
}
/**
* Redis is can connect
* @return string
* @author deng (2019/9/4 17:53)
*/
public static function connect()
{
// 如果连接资源不存在,则进行资源连接
if (!self::$_connectSource)
{
//@return bool TRUE on success, FALSE on error.
self::$_connectSource = self::getInstance()->connect('127.0.0.1',6379,9000);
// 没有资源返回
if (!self::$_connectSource)
{
return 'Redis Server Connection Fail';
}
}
return self::$_connectSource;
}
}
//RedisInstance::getInstance()->set('test','test');