From e4958bd824064948bc66fb94482f9fe24722e736 Mon Sep 17 00:00:00 2001 From: han chiang Date: Sun, 8 May 2022 11:05:07 +0800 Subject: [PATCH] Add sample commands, update readme. --- README.md | 92 ++++++++++++++++++++++++++-------- examples/echo.txt | 6 +++ examples/get.txt | 5 ++ examples/get_key_not_found.txt | 5 ++ examples/ping.txt | 3 ++ examples/set.txt | 7 +++ examples/set_with_expiry.txt | 12 +++++ 7 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 examples/echo.txt create mode 100644 examples/get.txt create mode 100644 examples/get_key_not_found.txt create mode 100644 examples/ping.txt create mode 100644 examples/set.txt create mode 100644 examples/set_with_expiry.txt diff --git a/README.md b/README.md index 1d45558..f13a0c5 100644 --- a/README.md +++ b/README.md @@ -39,34 +39,48 @@ Note: This section is for stages 2 and beyond. * `tests/`: Integration tests * `mod.rs`: Module exporters * `*.rs`: Test files +* `examples/`: Sample commands for client to send to the server # Set up project * Install [rust](https://www.rust-lang.org/tools/install), which comes with [Cargo](https://doc.rust-lang.org/cargo/) -* Start TCP server at port 6379: `./spawn_redis_server.sh` +* Start TCP server at port 6379: `./spawn_redis_server.sh` or `cargo run` * Connect to TCP server: `nc localhost 6379` -* Run redis commands: PING, ECHO, GET, SET(support PX) +* Enter redis commands: PING, ECHO, GET, SET(supports expiry with PX) + * Alternatively, use the commands in `examples/`, e.g. `nc localhost 6379 < examples/ping.txt` * Run tests: `cargo test --features init_redis_test` * Run only unit tests: `cargo test --features init_redis_test --lib` * Run only integration tests: `cargo test --features init_redis_test --test '*'` **Sample commands** -PING +PING: ``` -*1\r\n$4\r\n -ping\r\n +*1 +$4 +ping + ``` +or +`nc localhost 6379 < examples/ping.txt` + Output: ``` +PONG ``` -ECHO +ECHO: ``` -*2\r\n$4\r\n -echo\r\n$11\r\n -hello world\r\n +*2 +$4 +echo +$11 +hello world + ``` + +or +`nc localhost 6379 < examples/echo.txt` + Output: ``` $11 @@ -75,11 +89,19 @@ hello world SET ``` -*3\r\n$3\r\nSET\r\n -$5\r\nhello\r\n -$5\r\nworld\r\n +*3 +$3 +SET +$5 +hello +$5 +world + ``` +or +`nc localhost 6379 < examples/set.txt` + Output: ``` $2 @@ -88,12 +110,24 @@ OK SET with 5 seconds expiry ``` -*5\r\n$3\r\nSET\r\n -$5\r\nhello\r\n -$5\r\nworld\r\n -$2\r\npx\r\n -$4\r\n5000\r\n +*5 +$3 +SET +$5 +hello +$5 +world +$2 +px +$4 +5000 + ``` + + +or +`nc localhost 6379 < examples/set_with_expiry.txt` + Output: ``` $2 @@ -102,22 +136,36 @@ OK GET ``` -*2\r\n$3\r\nget\r\n -$5\r\nhello\r\n +*2 +$3 +get +$5 +hello + ``` +or +`nc localhost 6379 < examples/get.txt` + Output: ``` $5 world ``` -GET key that is not found +GET a key that is not found ``` -*2\r\n$3\r\nget\r\n -$6\r\nrandom\r\n +*2 +$3 +get +$6 +random + ``` +or +`nc localhost 6379 < examples/get_key_not_found.txt` + Output: ``` $-1 diff --git a/examples/echo.txt b/examples/echo.txt new file mode 100644 index 0000000..e792b79 --- /dev/null +++ b/examples/echo.txt @@ -0,0 +1,6 @@ +*2 +$4 +echo +$5 +hello + diff --git a/examples/get.txt b/examples/get.txt new file mode 100644 index 0000000..c62f99a --- /dev/null +++ b/examples/get.txt @@ -0,0 +1,5 @@ +*2 +$3 +get +$5 +hello diff --git a/examples/get_key_not_found.txt b/examples/get_key_not_found.txt new file mode 100644 index 0000000..d1472ae --- /dev/null +++ b/examples/get_key_not_found.txt @@ -0,0 +1,5 @@ +*2 +$3 +get +$6 +random diff --git a/examples/ping.txt b/examples/ping.txt new file mode 100644 index 0000000..5aa3a64 --- /dev/null +++ b/examples/ping.txt @@ -0,0 +1,3 @@ +*1 +$4 +ping diff --git a/examples/set.txt b/examples/set.txt new file mode 100644 index 0000000..b884bbc --- /dev/null +++ b/examples/set.txt @@ -0,0 +1,7 @@ +*3 +$3 +set +$5 +hello +$5 +world diff --git a/examples/set_with_expiry.txt b/examples/set_with_expiry.txt new file mode 100644 index 0000000..9b96515 --- /dev/null +++ b/examples/set_with_expiry.txt @@ -0,0 +1,12 @@ +*5 +$3 +set +$5 +hello +$5 +world +$2 +px +$4 +5000 +