aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authoromagdy <omar.professional8777@gmail.com>2025-07-15 01:06:23 +0300
committeromagdy <omar.professional8777@gmail.com>2025-07-15 01:06:23 +0300
commitaa53605153722a3c68527ca30c33ddf89b422522 (patch)
tree7da75b7b95d9905ccbb7c25bbdea50e7f24b7f8e /src/main.rs
parent39183b7885d8204054c4d03c4df29825a8a605fa (diff)
downloadredis-rust-aa53605153722a3c68527ca30c33ddf89b422522.tar.xz
redis-rust-aa53605153722a3c68527ca30c33ddf89b422522.zip
test respond to multiple PINGs
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 20ceccd..464716f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,8 @@
#![allow(unused_imports)]
-use std::{io::Write, net::TcpListener};
+use std::{
+ io::{Read, Write},
+ net::TcpListener,
+};
fn main() {
let listener = TcpListener::bind("127.0.0.1:6379").unwrap();
@@ -7,7 +10,12 @@ fn main() {
for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
- stream.write_all(b"+PONG\r\n").unwrap();
+ let mut buf = [0; 128];
+ stream.read(&mut buf).unwrap();
+ let request = str::from_utf8(&buf).unwrap();
+ for _ in 0..request.matches("PING").count() {
+ stream.write_all(b"+PONG\r\n").unwrap();
+ }
}
Err(e) => {
println!("error: {}", e);