-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.php
69 lines (62 loc) · 1.66 KB
/
api.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
$func = $_REQUEST['func'];
$body = json_decode(file_get_contents('php://input'), true);
class Api
{
// 下发前端web展示的可访问redis链接列表
static function connections()
{
return [
['key' => '1', 'connectionName' => '测试连接']
];
}
static function redisInvoke($body)
{
$command = $body['command'];
$params = $body['params'];
// 可以根据这里的客户端转发上来的链接信息判断怎么连接指定redis
$connConfig = $body['connConfig'];
$redis = new Redis();
$redis->connect('127.0.0.1');
$writeCommand = [
'set',
'del',
'persist',
'expire',
'hset',
'call',
'lpush',
'rpush',
'sadd',
'hdel',
'rename',
'srem',
'zrem',
'zadd',
'lrem'
];
$readCommand = [
'scan',
'info',
'type',
'ttl',
'hlen',
'hscan',
'get',
'exists',
'llen',
'lrange',
'sscan',
'zcard',
'scard',
'zrevrange'
];
if (!in_array($command, $writeCommand)
|| !in_array($command, $readCommand)) {
return 'no allow command=[' . $command . ']';
}
$redis->setOption(Redis::OPT_REPLY_LITERAL, 1);
return $redis->rawCommand($command, ...$params);
}
}
echo json_encode(Api::$func($body), JSON_UNESCAPED_UNICODE);