Skip to main content

sierradb_server/request/
ping.rs

1use std::convert::Infallible;
2
3use combine::{Parser, value};
4use redis_protocol::resp3::types::BytesFrame;
5
6use crate::parser::FrameStream;
7use crate::request::{HandleRequest, simple_str};
8use crate::server::Conn;
9
10#[derive(Clone, Copy)]
11pub struct Ping {}
12
13impl Ping {
14    pub fn parser<'a>() -> impl Parser<FrameStream<'a>, Output = Ping> + 'a {
15        value(Ping {})
16    }
17}
18
19impl HandleRequest for Ping {
20    type Error = Infallible;
21    type Ok = PingResp;
22
23    async fn handle_request(self, _conn: &mut Conn) -> Result<Option<Self::Ok>, Self::Error> {
24        Ok(Some(PingResp))
25    }
26}
27
28pub struct PingResp;
29
30impl From<PingResp> for BytesFrame {
31    fn from(_: PingResp) -> Self {
32        simple_str("PONG")
33    }
34}