Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eaddingtonwhite
Copy link
Contributor

No description provided.

@@ -0,0 +1,59 @@
// Licensed under the Apache License, Version 2.0
Copy link
Collaborator

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
Copy link
Collaborator

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";
Copy link
Collaborator

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();
Copy link
Collaborator

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 _);
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

@brayniac
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants