15
15
Usage
16
16
-----
17
17
The usage is the same as bridgeclient.py
18
- You have just two methods: get and put (see example.php)
18
+ You have just three methods: get, put and getall (see example.php)
19
19
20
20
*/
21
21
@@ -39,14 +39,15 @@ private function disconnect() {
39
39
socket_close ($ this ->socket );
40
40
}
41
41
42
- private function sendcommand ($ command ,$ key ,$ value ="" ) {
42
+ private function sendcommand ($ command ,$ key= "" ,$ value ="" ) {
43
43
$ jsonreceive = "" ;
44
44
$ obraces =0 ;
45
45
$ cbraces =0 ;
46
46
47
47
$ this ->connect ();
48
48
49
- $ jsonsend = '{"command":" ' .$ command .'","key":" ' .$ key .'","value":" ' .$ value .'"} ' ;
49
+ if ($ key <>"" ){$ jsonsend = '{"command":" ' .$ command .'","key":" ' .$ key .'","value":" ' .$ value .'"} ' ;}
50
+ else {$ jsonsend = '{"command":" ' .$ command .'"} ' ;}
50
51
socket_write ($ this ->socket , $ jsonsend , strlen ($ jsonsend ));
51
52
52
53
do {
@@ -58,10 +59,15 @@ private function sendcommand($command,$key,$value="") {
58
59
59
60
$ this ->disconnect ();
60
61
61
- $ jsonarray =json_decode ($ jsonreceive );
62
- if ($ jsonarray ->{'value ' } == NULL ) $ jsonarray ->{'value ' }="None " ;
62
+ if ($ key <>"" ){
63
+ $ jsonarray =json_decode ($ jsonreceive );
64
+ if ($ jsonarray ->{'value ' } == NULL ) $ jsonarray ->{'value ' }="None " ;
63
65
64
- return $ jsonarray ->{'value ' };
66
+ return $ jsonarray ->{'value ' };
67
+ }
68
+ else {
69
+ return $ jsonreceive ;
70
+ }
65
71
}
66
72
67
73
public function get ($ key ) {
@@ -71,6 +77,10 @@ public function get($key) {
71
77
public function put ($ key ,$ value ) {
72
78
return $ this ->sendcommand ("put " ,$ key ,$ value );
73
79
}
80
+
81
+ public function getall () {
82
+ return $ this ->sendcommand ("get " );
83
+ }
74
84
75
85
}
76
86
?>
0 commit comments