-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyValueClient.py
36 lines (32 loc) · 1.03 KB
/
keyValueClient.py
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
from pymemcache.client.base import Client
import time
class KeyValueClient:
def __init__(self):
self.host = "0.0.0.0"
self.port = 9889
def setKey(self, key, value):
try:
client = Client(self.host + ":" + str(self.port), default_noreply=False, encoding='utf-8')
result = client.set(key, value)
client.close()
return result
except:
print('exception in set key')
def getKey(self, key):
try:
client = Client(self.host + ":" + str(self.port))
result = client.get(key)
client.close()
if result is None:
return result
return result.decode()
except Exception as e:
print("exception in get key", e)
def delete(self):
try:
client = Client(self.host + ":" + str(self.port))
result = client.delete("all")
time.sleep(0.1)
except:
print('error in client delete function')
return True