Skip to content

Commit

Permalink
docs: add how to use kvctl
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYunfeii committed Mar 3, 2023
1 parent b7fa5b4 commit 7dc83c7
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
53 changes: 39 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,52 @@
Developed command line tool **kvctl**.
value type:string
```shell
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate set --value hello
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate get

hello
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate set --value world --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key qjx --operate get --ip 43.143.229.22
+-------+
| Value |
+-------+
| world |
+-------+
```

value type:list
```shell
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value hello --encoding list
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value world --encoding list

yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate get

world hello
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value hello --encoding list --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate set --value world --encoding list --ip 43.143.229.22
+--------+
| Status |
+--------+
| OK |
+--------+
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --key zyf --operate get --ip 43.143.229.22
+-------+
| Value |
+-------+
| hello |
| world |
+-------+
```
search key using regex:
```shell
./kvctl --keyRex .* --operate findkey

zyf
qjx
yunfei@ubuntu:~/MiniKV/build$ ./kvctl --keyRex .* --operate findkey --ip 43.143.229.22
+--------+
| Key |
+--------+
| zyf |
| yunfei |
| qjx |
+--------+
```


Expand Down
6 changes: 4 additions & 2 deletions kvctl/config.flags
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--ip=43.143.229.22
--key=qjx
--operate=get
--key=zyf
--operate=set
--value=hello
--encoding=list
5 changes: 4 additions & 1 deletion kvctl/draw_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ void drawDatas(std::vector<int>& max, std::vector<std::vector<std::string>>& Str
drawLine(max, columns);
}

void maxLenForEveryCol(std::vector<std::vector<std::string>>& datas, std::vector<int>& maxLen) {
void maxLenForEveryCol(std::vector<std::vector<std::string>>& datas, std::vector<int>& maxLen, std::vector<std::string>& head) {
if (datas.empty()) return;
maxLen.resize(datas[0].size());
for (int i = 0; i < datas[0].size(); ++i) {
for (int j = 0; j < datas.size(); ++j) {
if (datas[j][i].size() > maxLen[i]) {
maxLen[i] = datas[j][i].size();
}
if (head[i].size() > maxLen[i]) {
maxLen[i] = head[i].size();
}
}

Expand Down
4 changes: 2 additions & 2 deletions kvctl/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ void drawStatus(int ans) {
std::vector<std::vector<std::string>> data;
data.push_back({enStatus[ans]});
std::vector<int> max;
maxLenForEveryCol(data, max);
std::vector<std::string> head = {"Status"};
maxLenForEveryCol(data, max, head);
drawDatas(max, data, head, 1, 1);
}

Expand All @@ -64,8 +64,8 @@ void drawMultiEleOneCol(std::vector<std::string>& ans, std::string headName) {
data.push_back({ans[i]});
}
std::vector<int> max;
maxLenForEveryCol(data, max);
std::vector<std::string> head = {headName};
maxLenForEveryCol(data, max, head);
drawDatas(max, data, head, 1, ans.size());
}

Expand Down
2 changes: 1 addition & 1 deletion server/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HashTable {
std::list<kvString>* p = (std::list<kvString>*)(i->get()->data.get());
char* valBuf = new char[val.size()];
memcpy(valBuf, val.data(), val.size());
p->push_front(kvString{(uint32_t)val.size(), std::shared_ptr<char[]>(valBuf)});
p->push_back(kvString{(uint32_t)val.size(), std::shared_ptr<char[]>(valBuf)});
} else if (i->get()->encoding == MiniKV_STRING) {
insertWithEncoding(i->get(), key, val, encoding);
}
Expand Down

0 comments on commit 7dc83c7

Please sign in to comment.