1extern crate resp_async;
2extern crate tokio;
3
4use bytes::Bytes;
5use resp_async::error::Result;
6use resp_async::{ConnectionInfo, Router, Server, ServerHooks, Value};
7
8struct Hooks;
9
10impl ServerHooks for Hooks {
11 fn on_connection_open(&self, info: ConnectionInfo) {
12 println!("client {} connected from {}", info.id, info.peer_addr);
13 }
14
15 fn on_connection_close(&self, info: ConnectionInfo) {
16 println!("client {} disconnected", info.id);
17 }
18}
19
20async fn ping() -> Value {
21 Value::Simple(Bytes::from_static(b"PONG"))
22}
23
24#[tokio::main]
25pub async fn main() -> Result<()> {
26 let app: Router<()> = Router::new().route("PING", ping);
27 Server::bind("0.0.0.0:6379")
28 .with_hooks(Hooks)
29 .serve(app)
30 .await
31}