Skip to content

Commit 5ab2307

Browse files
committed
redis 协程类封装
1 parent ae5f1ff commit 5ab2307

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Framework/Core/RedisCoroutine.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
namespace Framework\Core;
5+
6+
use Swoole\Coroutine\Redis;
7+
8+
class RedisCoroutine
9+
{
10+
public $connection;
11+
12+
public function __construct($config)
13+
{
14+
try {
15+
$this->connection = new Redis();
16+
$res = $this->connection->connect($config);
17+
if ($res == false) {
18+
//连接失败,抛弃常
19+
throw new \Exception("Failed to Connect Coroutine Redis Server.");
20+
}
21+
} catch (\Exception $e) {
22+
echo $e->getMessage() . "\r\n";
23+
return false;
24+
}
25+
26+
}
27+
28+
public function getConnection()
29+
{
30+
return $this->connection;
31+
}
32+
}

0 commit comments

Comments
 (0)