MCPcopy Create free account
hub / github.com/Firstyear/opensuse-proxy-cache / client_process

Function client_process

redis-server/src/main.rs:29–182  ·  view source on GitHub ↗
(
    mut r: FramedRead<R, RedisCodec>,
    mut w: FramedWrite<W, RedisCodec>,
    client_address: net::SocketAddr,
    mut shutdown_rx: broadcast::Receiver<()>,
    cache: Arc<CacheT>,
)

Source from the content-addressed store, hash-verified

27
28#[instrument(level = "debug", skip_all)]
29async fn client_process<W: AsyncWrite + Unpin, R: AsyncRead + Unpin>(
30 mut r: FramedRead<R, RedisCodec>,
31 mut w: FramedWrite<W, RedisCodec>,
32 client_address: net::SocketAddr,
33 mut shutdown_rx: broadcast::Receiver<()>,
34 cache: Arc<CacheT>,
35) {
36 info!(?client_address, "connect");
37
38 'outer: loop {
39 tokio::select! {
40 Ok(()) = (&mut shutdown_rx).recv() => {
41 break;
42 }
43 res = r.next() => {
44 let rmsg =
45 match res {
46 None => {
47 info!(?client_address, "none disconnect");
48 break;
49 }
50 Some(Err(e)) => {
51 error!(?e);
52 info!(?client_address, "err disconnect");
53 break;
54 }
55 Some(Ok(rmsg)) => {
56 rmsg
57 }
58 };
59
60 match rmsg {
61 RedisClientMsg::Auth(_passwd) => {
62 debug!("Handling Auth");
63 if let Err(e) = w.send(RedisServerMsg::Ok).await {
64 error!(?e);
65 break;
66 }
67 }
68 RedisClientMsg::Ping => {
69 debug!("Handling Ping");
70 if let Err(e) = w.send(RedisServerMsg::Pong).await {
71 error!(?e);
72 break;
73 }
74 }
75
76 RedisClientMsg::Info => {
77 debug!("Handling Info");
78 let stats = cache.view_stats();
79 let used_memory = stats.freq + stats.recent;
80 if let Err(e) = w.send(
81 RedisServerMsg::Info { used_memory }
82 ).await {
83 error!(?e);
84 break;
85 }
86 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected