Skip to content

Commit 7dc83c7

Browse files
committed
docs: add how to use kvctl
1 parent b7fa5b4 commit 7dc83c7

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

README.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,52 @@
55
Developed command line tool **kvctl**.
66
value type:string
77
```shell
8-
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate set --value hello
9-
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate get
10-
11-
hello
8+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate set --value world --ip 43.143.229.22
9+
+--------+
10+
| Status |
11+
+--------+
12+
| OK |
13+
+--------+
14+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate get --ip 43.143.229.22
15+
+-------+
16+
| Value |
17+
+-------+
18+
| world |
19+
+-------+
1220
```
1321

1422
value type:list
1523
```shell
16-
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value hello --encoding list
17-
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value world --encoding list
18-
19-
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate get
20-
21-
world hello
24+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value hello --encoding list --ip 43.143.229.22
25+
+--------+
26+
| Status |
27+
+--------+
28+
| OK |
29+
+--------+
30+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value world --encoding list --ip 43.143.229.22
31+
+--------+
32+
| Status |
33+
+--------+
34+
| OK |
35+
+--------+
36+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate get --ip 43.143.229.22
37+
+-------+
38+
| Value |
39+
+-------+
40+
| hello |
41+
| world |
42+
+-------+
2243
```
2344
search key using regex:
2445
```shell
25-
./kvctl --keyRex .* --operate findkey
26-
27-
zyf
28-
qjx
46+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --keyRex .* --operate findkey --ip 43.143.229.22
47+
+--------+
48+
| Key |
49+
+--------+
50+
| zyf |
51+
| yunfei |
52+
| qjx |
53+
+--------+
2954
```
3055

3156

kvctl/config.flags

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
--ip=43.143.229.22
2-
--key=qjx
3-
--operate=get
2+
--key=zyf
3+
--operate=set
4+
--value=hello
5+
--encoding=list

kvctl/draw_table.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ void drawDatas(std::vector<int>& max, std::vector<std::vector<std::string>>& Str
3131
drawLine(max, columns);
3232
}
3333

34-
void maxLenForEveryCol(std::vector<std::vector<std::string>>& datas, std::vector<int>& maxLen) {
34+
void maxLenForEveryCol(std::vector<std::vector<std::string>>& datas, std::vector<int>& maxLen, std::vector<std::string>& head) {
3535
if (datas.empty()) return;
3636
maxLen.resize(datas[0].size());
3737
for (int i = 0; i < datas[0].size(); ++i) {
3838
for (int j = 0; j < datas.size(); ++j) {
3939
if (datas[j][i].size() > maxLen[i]) {
4040
maxLen[i] = datas[j][i].size();
41+
}
42+
if (head[i].size() > maxLen[i]) {
43+
maxLen[i] = head[i].size();
4144
}
4245
}
4346

kvctl/main.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void drawStatus(int ans) {
5353
std::vector<std::vector<std::string>> data;
5454
data.push_back({enStatus[ans]});
5555
std::vector<int> max;
56-
maxLenForEveryCol(data, max);
5756
std::vector<std::string> head = {"Status"};
57+
maxLenForEveryCol(data, max, head);
5858
drawDatas(max, data, head, 1, 1);
5959
}
6060

@@ -64,8 +64,8 @@ void drawMultiEleOneCol(std::vector<std::string>& ans, std::string headName) {
6464
data.push_back({ans[i]});
6565
}
6666
std::vector<int> max;
67-
maxLenForEveryCol(data, max);
6867
std::vector<std::string> head = {headName};
68+
maxLenForEveryCol(data, max, head);
6969
drawDatas(max, data, head, 1, ans.size());
7070
}
7171

server/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class HashTable {
7777
std::list<kvString>* p = (std::list<kvString>*)(i->get()->data.get());
7878
char* valBuf = new char[val.size()];
7979
memcpy(valBuf, val.data(), val.size());
80-
p->push_front(kvString{(uint32_t)val.size(), std::shared_ptr<char[]>(valBuf)});
80+
p->push_back(kvString{(uint32_t)val.size(), std::shared_ptr<char[]>(valBuf)});
8181
} else if (i->get()->encoding == MiniKV_STRING) {
8282
insertWithEncoding(i->get(), key, val, encoding);
8383
}

0 commit comments

Comments
 (0)