@@ -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}
0 commit comments