Skip to content

Commit 9de2793

Browse files
author
Federico Fissore
committed
bridgeclient: added 'delete' function to both python and php clients
1 parent 72eef38 commit 9de2793

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

bridge/bridgeclient.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@ def put(self, key, value):
7272
r = self.wait_key(key, json, 10)
7373
json.close()
7474
return r
75+
76+
def delete(self, key):
77+
json = TCPJSONClient('127.0.0.1', 5700)
78+
json.send({'command': 'delete', 'key': key})
79+
r = self.wait_response(json, 10)
80+
if not r is None and not r['value'] is None:
81+
r = r['value']
82+
json.close()
83+
return r

bridge/bridgeclient_example.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616

1717
print
1818

19+
print 'Assigning value to key D12'
20+
client.put('D12', 'Test D12')
21+
22+
test = client.get('D12')
23+
print 'Value assigned to D12 is ' + test
24+
25+
print 'Deleting key D12'
26+
client.delete('D12')
27+
test = client.get('D12')
28+
print 'Value assigned to D12 is ' + str(test)
29+
30+
print
31+
1932
print 'Assigning value to key D11'
2033
client.put('D11', 'Test D11')
2134

bridge/php/bridgeclient.class.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ private function sendcommand($command, $key = "", $value = "") {
4444

4545
$this->connect();
4646

47+
$jsonsend = new stdClass();
48+
$jsonsend->command = $command;
4749
if ($key <> "") {
48-
$jsonsend = "{\"command\":\"" . $command . "\",\"key\":\"" . $key . "\",\"value\":\"" . $value . "\"}";
49-
} else {
50-
$jsonsend = "{\"command\":\"" . $command . "\"}";
50+
$jsonsend->key = $key;
5151
}
52+
if ($value <> "") {
53+
$jsonsend->value = $value;
54+
}
55+
$jsonsend = json_encode($jsonsend);
56+
5257
socket_write($this->socket, $jsonsend, strlen($jsonsend));
5358

5459
do {
@@ -76,12 +81,16 @@ public function get($key) {
7681
return $this->sendcommand("get", $key);
7782
}
7883

84+
public function getall() {
85+
return $this->sendcommand("get");
86+
}
87+
7988
public function put($key, $value) {
8089
return $this->sendcommand("put", $key, $value);
8190
}
8291

83-
public function getall() {
84-
return $this->sendcommand("get");
92+
public function delete($key) {
93+
return $this->sendcommand("delete", $key);
8594
}
8695
}
8796

bridge/php/example.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111

1212
print("\n");
1313

14+
print("Assigning value to key D12\n");
15+
$client->put("D12", "Test D12");
16+
17+
$test = $client->get("D12");
18+
print("Value assigned to D12 is " . $test . "\n");
19+
20+
print("Deleting key D12\n");
21+
$client->delete("D12");
22+
$test = $client->get("D12");
23+
print("Value assigned to D12 is " . $test . "\n");
24+
25+
print("\n");
26+
1427
print("Assigning value to key D11\n");
1528
$client->put("D11", "Test D11");
1629

0 commit comments

Comments
 (0)