-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (40 loc) Β· 1.33 KB
/
main.py
File metadata and controls
49 lines (40 loc) Β· 1.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
import cmd
from lsm.kvstore import KVStore
class LSMKVShell(cmd.Cmd):
intro = "ποΈ Welcome to the LSM KVStore shell. Type help or ? to list commands.\n"
prompt = "kvstore> "
def __init__(self):
super().__init__()
self.store = KVStore()
def do_set(self, arg: str) -> None:
"Set a key-value pair: set <key> <value>"
parts = arg.strip().split()
if len(parts) != 2:
print("β Usage: set <key> <value>")
return
key, value = parts
self.store.set(key, value)
print(f"β
Set key: {key}")
def do_get(self, arg: str) -> None:
"Get a value by key: get <key>"
key = arg.strip()
if not key:
print("β Usage: get <key>")
return
value = self.store.get(key)
if value is not None:
print(f"π {key} = {value}")
else:
print("β Key not found.")
def do_flush(self, arg: str) -> None:
"Flush MemTable to SSTable"
self.store.flush()
print("πΎ Flushed MemTable to SSTable.")
def do_exit(self, arg: str) -> bool:
"Exit the shell"
print("π Exiting KVStore.")
return True
def do_EOF(self, arg: str) -> bool:
return self.do_exit(arg)
if __name__ == "__main__":
LSMKVShell().cmdloop()