Skip to content

Commit 4cb33ed

Browse files
author
zng
committed
出错时返回false
1 parent faf8199 commit 4cb33ed

File tree

2 files changed

+18
-41
lines changed

2 files changed

+18
-41
lines changed

Seefan/Service/Kv.php

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,71 +8,44 @@ public function __construct($base_url, $http)
88
$this->name = 'kv';
99
}
1010

11-
/**
12-
* 删除指定键值
13-
*
14-
* @param string $key 键
15-
*
16-
* @return bool 是否删除成功
17-
*/
11+
public function get($key)
12+
{
13+
$url = $this->name . '/' . $key;
14+
$resp = $this->http->request($this->base_url . $url);
15+
return $this->response($resp);
16+
}
17+
1818
public function delete($key)
1919
{
2020
$url = $this->name . '/' . $key;
2121
$resp = $this->http->request($this->base_url . $url, '', 'DELETE');
2222
return $resp == 'true';
2323
}
2424

25-
/**
26-
* 设置键值
27-
*
28-
* @param string $key 键
29-
* @param string $value 值
30-
*
31-
* @return bool 是否设置成功
32-
*/
3325
public function set($key, $value)
3426
{
3527
$url = $this->name . '/' . $key;
3628
$resp = $this->http->request($this->base_url . $url, $value, 'PUT');
3729
return $resp == 'true';
3830
}
3931

40-
/**
41-
* 获取指定键的值
42-
*
43-
* @param string $key 键
44-
*
45-
* @return string 值
46-
*/
47-
public function get($key)
48-
{
49-
$url = $this->name . '/' . $key;
50-
$resp = $this->http->request($this->base_url . $url);
51-
return $this->response($resp);
52-
}
53-
54-
/**
55-
* 返回指定键下的键名列表,如果指定键下还有子级的话
56-
*
57-
* @param string $key
58-
*
59-
* @return mixed|string
60-
*/
6132
public function keys($key = '')
6233
{
6334
$url = $this->name . '/' . $key . '?keys';
6435
$resp = $this->http->request($this->base_url . $url);
6536
return parent::response($resp);
6637
}
6738

68-
protected function response($str)
39+
public function response($str)
6940
{
70-
if (!empty($str)) {
71-
$json = json_decode($str, true);
41+
$json = parent::response($str);
42+
if (is_array($json)) {
7243
if (count($json) > 0) {
7344
return base64_decode($json[0]['Value']);
7445
}
46+
} else {
47+
return $json;
7548
}
76-
return '';
49+
return false;
7750
}
7851
}

Seefan/Service/Service.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
namespace Seefan\Service;
3+
34
use Seefan\Http;
45

56
class Service
@@ -11,8 +12,11 @@ class Service
1112
protected $base_url = '';
1213
public $name = 'agent';
1314

14-
protected function response($str)
15+
public function response($str)
1516
{
17+
if ($str === false) {
18+
return false;
19+
}
1620
if (empty($str)) {
1721
return '';
1822
}

0 commit comments

Comments
 (0)