-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRedisTest.php
More file actions
48 lines (40 loc) · 1017 Bytes
/
RedisTest.php
File metadata and controls
48 lines (40 loc) · 1017 Bytes
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
<?php
namespace Utopia\Tests;
use Redis;
use Utopia\Abuse\Adapters\TimeLimit;
use Utopia\Abuse\Adapters\TimeLimit\Redis as AdapterRedis;
use Utopia\Exception;
class RedisTest extends Base
{
protected static \Redis $redis;
/**
* @throws Exception
* @throws \Exception
*/
public static function setUpBeforeClass(): void
{
if (isset(self::$redis)) {
return;
}
self::$redis = self::initialiseRedis();
}
protected static function initialiseRedis(): \Redis
{
$redis = new \Redis();
$redis->connect('redis', 6379);
return $redis;
}
public function getAdapter(string $key, int $limit, int $seconds): TimeLimit
{
return new AdapterRedis($key, $limit, $seconds, self::$redis);
}
/**
* Clean up Redis connection after all tests
*/
public static function tearDownAfterClass(): void
{
if (isset(self::$redis)) {
self::$redis->close();
}
}
}