Skip to content
Permalink
Browse files

Only save writes (like 'set' and 'delete') to server logs—-no reads (…

…like 'get' or 'show')
  • Loading branch information
chelseatroy committed Dec 18, 2019
1 parent 98b782f commit e4f04e7b79f5af16ca563799e23797d4ca769f81
Showing with 8 additions and 5 deletions.
  1. +8 −5 key_value_store.py
@@ -31,10 +31,6 @@ def catch_up(self):
def execute(self, string_operation):
self.log.append(string_operation)

f = open(self.server_name + "_log.txt", "a+")
f.write(string_operation + '\n')
f.close()

command, key = 0, 1
operands = string_operation.split(" ")

@@ -45,14 +41,21 @@ def execute(self, string_operation):
response = self.get(operands[key])
elif operands[command] == "set":
value = " ".join(operands[2:])
self.write_to_log(string_operation)
self.set(operands[key], value)
response = f"key {operands[key]} set to {value}"
elif operands[command] == "delete":
self.write_to_log(string_operation)
self.delete(operands[key])
response = f"key {key} deleted"
elif operands[command] == "show":
response = str(self.data)
else:
pass

return response
return response

def write_to_log(self, string_operation):
f = open(self.server_name + "_log.txt", "a+")
f.write(string_operation + '\n')
f.close()

0 comments on commit e4f04e7

Please sign in to comment.
You can’t perform that action at this time.