-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds PING support to momento proxy resp impl #6
base: main
Are you sure you want to change the base?
feat: adds PING support to momento proxy resp impl #6
Conversation
@@ -0,0 +1,59 @@ | |||
// Licensed under the Apache License, Version 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add the Pelikan Foundation LLC as the copyright holder w/ 2022 year.
@@ -0,0 +1,22 @@ | |||
// Licensed under the Apache License, Version 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
use session::{SESSION_SEND, SESSION_SEND_BYTE, SESSION_SEND_EX}; | ||
use tokio::io::AsyncWriteExt; | ||
|
||
const PONG_RSP: &[u8; 7] = b"+PONG\r\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this wasn't implemented in the RESP protocol instead?
const PONG_RSP: &[u8; 7] = b"+PONG\r\n"; | ||
|
||
pub async fn ping(socket: &mut tokio::net::TcpStream) -> Result<(), Error> { | ||
let mut response_buf = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do all this w/o allocating here
let mut response_buf = Vec::new(); | ||
response_buf.extend_from_slice(PONG_RSP); | ||
SESSION_SEND.increment(); | ||
SESSION_SEND_BYTE.add(response_buf.len() as _); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PONG_RSP.len()
should work too?
SESSION_SEND.increment(); | ||
SESSION_SEND_BYTE.add(response_buf.len() as _); | ||
TCP_SEND_BYTE.add(response_buf.len() as _); | ||
if let Err(e) = socket.write_all(&response_buf).await { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you could .write_all(PONG_RSP)
here?
Overall, this works. I think it'd be cleaner for the pong response to be part of the RESP protocol implementation, as that will be useful when we add a redis compatible backend. |
No description provided.